mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-04-24 03:00:11 -04:00
Move all my plugins
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
var AppPreferences = function () {};
|
||||
|
||||
var AppPreferencesError = function(code, message) {
|
||||
this.code = code || null;
|
||||
this.message = message || '';
|
||||
};
|
||||
|
||||
AppPreferencesError.NO_PROPERTY = 0;
|
||||
AppPreferencesError.NO_PREFERENCE_ACTIVITY = 1;
|
||||
|
||||
AppPreferences.prototype.get = function(key,success,fail) {
|
||||
cordova.exec(success,fail,"applicationPreferences","get",[key]);
|
||||
};
|
||||
|
||||
AppPreferences.prototype.set = function(key,value,success,fail) {
|
||||
cordova.exec(success,fail,"applicationPreferences","set",[key, value]);
|
||||
};
|
||||
|
||||
AppPreferences.prototype.load = function(success,fail) {
|
||||
cordova.exec(success,fail,"applicationPreferences","load",[]);
|
||||
};
|
||||
|
||||
AppPreferences.prototype.show = function(activity,success,fail) {
|
||||
cordova.exec(success,fail,"applicationPreferences","show",[activity]);
|
||||
};
|
||||
|
||||
cordova.addConstructor(function() {
|
||||
cordova.addPlugin("applicationPreferences", new AppPreferences());
|
||||
});
|
||||
@@ -1,87 +0,0 @@
|
||||
package com.simonmacdonald.prefs;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
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 android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class AppPreferences extends Plugin {
|
||||
|
||||
private static final String LOG_TAG = "AppPrefs";
|
||||
private static final int NO_PROPERTY = 0;
|
||||
private static final int NO_PREFERENCE_ACTIVITY = 1;
|
||||
|
||||
@Override
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.ctx.getContext());
|
||||
|
||||
try {
|
||||
if (action.equals("get")) {
|
||||
String key = args.getString(0);
|
||||
if (sharedPrefs.contains(key)) {
|
||||
Object obj = sharedPrefs.getAll().get(key);
|
||||
return new PluginResult(status, obj.toString());
|
||||
} else {
|
||||
return createErrorObj(NO_PROPERTY, "No such property called " + key);
|
||||
}
|
||||
} else if (action.equals("set")) {
|
||||
String key = args.getString(0);
|
||||
String value = args.getString(1);
|
||||
if (sharedPrefs.contains(key)) {
|
||||
Editor editor = sharedPrefs.edit();
|
||||
if ("true".equals(value.toLowerCase()) || "false".equals(value.toLowerCase())) {
|
||||
editor.putBoolean(key, Boolean.parseBoolean(value));
|
||||
} else {
|
||||
editor.putString(key, value);
|
||||
}
|
||||
return new PluginResult(status, editor.commit());
|
||||
} else {
|
||||
return createErrorObj(NO_PROPERTY, "No such property called " + key);
|
||||
}
|
||||
} else if (action.equals("load")) {
|
||||
JSONObject obj = new JSONObject();
|
||||
Map prefs = sharedPrefs.getAll();
|
||||
Iterator it = prefs.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pairs = (Map.Entry)it.next();
|
||||
obj.put(pairs.getKey().toString(), pairs.getValue().toString());
|
||||
}
|
||||
return new PluginResult(status, obj);
|
||||
} else if (action.equals("show")) {
|
||||
String activityName = args.getString(0);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setClassName(this.ctx.getContext(), activityName);
|
||||
try {
|
||||
this.ctx.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
return createErrorObj(NO_PREFERENCE_ACTIVITY, "No preferences activity called " + activityName);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
status = PluginResult.Status.JSON_EXCEPTION;
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
|
||||
private PluginResult createErrorObj(int code, String message) throws JSONException {
|
||||
JSONObject errorObj = new JSONObject();
|
||||
errorObj.put("code", code);
|
||||
errorObj.put("message", message);
|
||||
return new PluginResult(PluginResult.Status.ERROR, errorObj);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
# Application Preferences plugin for Phonegap #
|
||||
Originally by Simon MacDonald (@macdonst)
|
||||
|
||||
Please note that the following steps are for PhoneGap 2.0
|
||||
|
||||
Information on writing plugins for PhoneGap 2.0 was taken from [this blog](http://simonmacdonald.blogspot.com/2012/08/so-you-wanna-write-phonegap-200-android.html) by Simon MacDonald (@macdonst)
|
||||
|
||||
## Adding the Plugin to your project ##
|
||||
|
||||
1) To install the plugin, move applicationPreferences.js to your project's www folder and include a reference to it in your html files.
|
||||
|
||||
`<script type="text/javascript" charset="utf-8" src="applicationPreferences.js"></script>`
|
||||
|
||||
2) Create a folder called 'com/simonmacdonald/prefs' within your project's src folder.
|
||||
3) And copy the AppPreferences.java file into that new folder.
|
||||
|
||||
`mkdir <your_project>/src/com/simonmacdonald/prefs`
|
||||
|
||||
`cp ./src/com/simonmacdonald/prefs/AppPreferences.java <your_project>/src/com/simonmacdonald/prefs`
|
||||
|
||||
4) In your `res/xml/config.xml` file add the following element as a child to the `<plugins>` element.
|
||||
|
||||
`<plugin name="applicationPreferences" value="com.simonmacdonald.prefs.AppPreferences"/>`
|
||||
|
||||
## Using the plugin ##
|
||||
|
||||
Create an object to be used to call the defined plugin methods.
|
||||
|
||||
var preferences = cordova.require("cordova/plugin/applicationpreferences");
|
||||
|
||||
The `preferences` object created above will be used in the following examples.
|
||||
|
||||
### get ###
|
||||
|
||||
In order to get the value a property you would call the get method.
|
||||
|
||||
/**
|
||||
* Get the value of the named property.
|
||||
*
|
||||
* @param key
|
||||
*/
|
||||
get(key, success, fail)
|
||||
|
||||
Sample use:
|
||||
|
||||
preferences.get("myKey", function(value) {
|
||||
alert("Value is " + value);
|
||||
}, function(error) {
|
||||
alert("Error! " + JSON.stringify(error));
|
||||
});
|
||||
|
||||
### set ###
|
||||
|
||||
In order to set the value a property you would call the set method.
|
||||
|
||||
/**
|
||||
* Set the value of the named property.
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
set(key, value, success, fail)
|
||||
|
||||
Sample use:
|
||||
|
||||
preferences.set("myKey", "myValue", function() {
|
||||
alert("Successfully saved!");
|
||||
}, function(error) {
|
||||
alert("Error! " + JSON.stringify(error));
|
||||
});
|
||||
|
||||
|
||||
### remove ###
|
||||
|
||||
In order to remove a key along with the value, you would call the remove method.
|
||||
|
||||
/**
|
||||
* Remove the key along with the value
|
||||
*
|
||||
* @param key
|
||||
*/
|
||||
remove(key, success, fail)
|
||||
|
||||
Sample use:
|
||||
|
||||
preferences.remove("myKey", function(value) {
|
||||
alert("Value removed!");
|
||||
}, function(error) {
|
||||
alert("Error! " + JSON.stringify(error));
|
||||
});
|
||||
|
||||
### clear ###
|
||||
|
||||
In order to remove all shared preferences, you would call the clear method.
|
||||
|
||||
/**
|
||||
* Clear all shared preferences
|
||||
*
|
||||
*/
|
||||
clear(success, fail)
|
||||
|
||||
Sample use:
|
||||
|
||||
preferences.clear(function() {
|
||||
alert("Cleared all preferences!");
|
||||
}, function(error) {
|
||||
alert("Error! " + JSON.stringify(error));
|
||||
});
|
||||
|
||||
### load ###
|
||||
|
||||
In order to get all the properties you can call the load method. The success callback of the load method will be called with a JSONObject which contains all the preferences.
|
||||
|
||||
/**
|
||||
* Get all the preference values.
|
||||
*
|
||||
*/
|
||||
load(success, fail)
|
||||
|
||||
Sample use:
|
||||
|
||||
preferences.load(function(prefs) {
|
||||
alert(JSON.stringify(prefs));
|
||||
}, function() {
|
||||
alert("Error! " + JSON.stringify(error));
|
||||
});
|
||||
|
||||
### show ###
|
||||
|
||||
If you want to load the PreferenceActivity of your application that displays all the preferences you can call the show method with the class name.
|
||||
|
||||
/**
|
||||
* Get all the preference values.
|
||||
*
|
||||
*/
|
||||
show(activity, success, fail)
|
||||
|
||||
Sample use:
|
||||
|
||||
function showPreferenceActivity() {
|
||||
preferences.show("com.ranhiru.apppreferences.PreferenceActivity", function() {
|
||||
alert("Showing Preferences Activity!");
|
||||
}, function(error) {
|
||||
alert("Error! " + JSON.stringify(error));
|
||||
});
|
||||
}
|
||||
|
||||
## Licence ##
|
||||
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2012 Simon MacDonald
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -1,39 +0,0 @@
|
||||
cordova.define("cordova/plugin/applicationpreferences", function(require, exports, module) {
|
||||
var exec = require("cordova/exec");
|
||||
var AppPreferences = function () {};
|
||||
|
||||
var AppPreferencesError = function(code, message) {
|
||||
this.code = code || null;
|
||||
this.message = message || '';
|
||||
};
|
||||
|
||||
AppPreferencesError.NO_PROPERTY = 0;
|
||||
AppPreferencesError.NO_PREFERENCE_ACTIVITY = 1;
|
||||
|
||||
AppPreferences.prototype.get = function(key,success,fail) {
|
||||
cordova.exec(success,fail,"applicationPreferences","get",[key]);
|
||||
};
|
||||
|
||||
AppPreferences.prototype.set = function(key,value,success,fail) {
|
||||
cordova.exec(success,fail,"applicationPreferences","set",[key, value]);
|
||||
};
|
||||
|
||||
AppPreferences.prototype.load = function(success,fail) {
|
||||
cordova.exec(success,fail,"applicationPreferences","load",[]);
|
||||
};
|
||||
|
||||
AppPreferences.prototype.show = function(activity,success,fail) {
|
||||
cordova.exec(success,fail,"applicationPreferences","show",[activity]);
|
||||
};
|
||||
|
||||
AppPreferences.prototype.clear = function(success,fail) {
|
||||
cordova.exec(success,fail,"applicationPreferences","clear", []);
|
||||
};
|
||||
|
||||
AppPreferences.prototype.remove = function(keyToRemove, success,fail) {
|
||||
cordova.exec(success,fail,"applicationPreferences","remove", [keyToRemove]);
|
||||
};
|
||||
|
||||
var appPreferences = new AppPreferences();
|
||||
module.exports = appPreferences;
|
||||
});
|
||||
@@ -1,97 +0,0 @@
|
||||
package com.simonmacdonald.prefs;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
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 android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class AppPreferences extends Plugin {
|
||||
|
||||
private static final String LOG_TAG = "AppPrefs";
|
||||
private static final int NO_PROPERTY = 0;
|
||||
private static final int NO_PREFERENCE_ACTIVITY = 1;
|
||||
|
||||
@Override
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.cordova.getActivity());
|
||||
|
||||
try {
|
||||
if (action.equals("get")) {
|
||||
String key = args.getString(0);
|
||||
if (sharedPrefs.contains(key)) {
|
||||
Object obj = sharedPrefs.getAll().get(key);
|
||||
return new PluginResult(status, obj.toString());
|
||||
} else {
|
||||
return createErrorObj(NO_PROPERTY, "No such property called " + key);
|
||||
}
|
||||
} else if (action.equals("set")) {
|
||||
String key = args.getString(0);
|
||||
String value = args.getString(1);
|
||||
Editor editor = sharedPrefs.edit();
|
||||
if ("true".equals(value.toLowerCase()) || "false".equals(value.toLowerCase())) {
|
||||
editor.putBoolean(key, Boolean.parseBoolean(value));
|
||||
} else {
|
||||
editor.putString(key, value);
|
||||
}
|
||||
return new PluginResult(status, editor.commit());
|
||||
} else if (action.equals("load")) {
|
||||
JSONObject obj = new JSONObject();
|
||||
Map prefs = sharedPrefs.getAll();
|
||||
Iterator it = prefs.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pairs = (Map.Entry)it.next();
|
||||
obj.put(pairs.getKey().toString(), pairs.getValue().toString());
|
||||
}
|
||||
return new PluginResult(status, obj);
|
||||
} else if (action.equals("show")) {
|
||||
String activityName = args.getString(0);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setClassName(this.cordova.getActivity(), activityName);
|
||||
try {
|
||||
this.cordova.getActivity().startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
return createErrorObj(NO_PREFERENCE_ACTIVITY, "No preferences activity called " + activityName);
|
||||
}
|
||||
} else if (action.equals("clear")) {
|
||||
Editor editor = sharedPrefs.edit();
|
||||
editor.clear();
|
||||
return new PluginResult(status, editor.commit());
|
||||
} else if (action.equals("remove")) {
|
||||
String key = args.getString(0);
|
||||
if (sharedPrefs.contains(key)) {
|
||||
Editor editor = sharedPrefs.edit();
|
||||
editor.remove(key);
|
||||
return new PluginResult(status, editor.commit());
|
||||
} else {
|
||||
return createErrorObj(NO_PROPERTY, "No such property called " + key);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
status = PluginResult.Status.JSON_EXCEPTION;
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
|
||||
private PluginResult createErrorObj(int code, String message) throws JSONException {
|
||||
JSONObject errorObj = new JSONObject();
|
||||
errorObj.put("code", code);
|
||||
errorObj.put("message", message);
|
||||
return new PluginResult(PluginResult.Status.ERROR, errorObj);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
MIT License (2008). As a recipient of PhonegGap, you may choose which
|
||||
license to receive this code under (except as noted in per-module LICENSE
|
||||
files). Some modules may not be the copyright of Nitobi. These
|
||||
modules contain explicit declarations of copyright in both the LICENSE files in
|
||||
the directories in which they reside and in the code itself. No external
|
||||
contributions are allowed under licenses which are fundamentally incompatible
|
||||
with the MIT or BSD licenses that PhoneGap is distributed under.
|
||||
|
||||
The text of the MIT and BSD licenses is reproduced below.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
The "New" BSD License:
|
||||
**********************
|
||||
|
||||
Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of Phonegap/Nitobi nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
The MIT License
|
||||
*****************
|
||||
|
||||
Copyright (c) <2010> <Nitobi Software Inc., et. al., >
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -1,147 +0,0 @@
|
||||
# FtpClient plugin for Phonegap #
|
||||
|
||||
The ftp client allows you to upload and download files from within your PhoneGap application.
|
||||
|
||||
A simple use case would be:
|
||||
|
||||
- Downloading a text file from a FTP server in order to be displayed in your application.
|
||||
- Uploading a text file to a FTP server.
|
||||
|
||||
## Adding the Plugin to your project ##
|
||||
|
||||
Using this plugin requires [Android PhoneGap](http://github.com/phonegap/phonegap-android).
|
||||
|
||||
1. To install the plugin, move www/ftpclient.js to your project's www folder and include a reference to it in your html file after phonegap.js.
|
||||
|
||||
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script><br/>
|
||||
<script type="text/javascript" charset="utf-8" src="ftpclient.js"></script>
|
||||
|
||||
2. Create a directory within your project called "src/com/phonegap/plugins/ftpclient" and copy src/com/phonegap/plugins/ftpclient/FtpClient.java into it.
|
||||
|
||||
3. Add the following activity to your AndroidManifest.xml file. It should be added inside the <application> tag.
|
||||
|
||||
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name"><br/>
|
||||
<intent-filter><br/>
|
||||
</intent-filter><br/>
|
||||
</activity>
|
||||
|
||||
4. Copy "libs/commons-net-2.2.jar" into the libs directory within your project. You will also need to right click on this file in eclipse and add the jar to the build path.
|
||||
|
||||
5. In your res/xml/plugins.xml file add the following line:
|
||||
|
||||
<plugin name="FtpClient" value="com.phonegap.plugins.ftpclient.FtpClient"/>
|
||||
|
||||
## Using the plugin ##
|
||||
|
||||
The plugin creates the object `window.plugins.ftpclient`. To use, call one of the following, available methods:
|
||||
|
||||
<pre>
|
||||
/**
|
||||
* Upload a file with the specified URL.
|
||||
*
|
||||
* @param file The file to upload
|
||||
* @param url The url of the ftp server
|
||||
* @param win The success callback
|
||||
* @param fail The error callback
|
||||
*/
|
||||
|
||||
put(file, url, win, fail);
|
||||
</pre>
|
||||
|
||||
Sample use:
|
||||
|
||||
window.plugins.ftpclient.put("test.txt", "ftp://username:password@ftp.server.com/test.txt;type=i", win, fail);
|
||||
|
||||
<pre>
|
||||
/**
|
||||
* Download a file with the specified URL.
|
||||
*
|
||||
* @param file The name of the local file to be saved
|
||||
* @param url The url of the ftp server
|
||||
* @param win The success callback
|
||||
* @param fail The error callback
|
||||
*/
|
||||
|
||||
get(file, url, win, fail);
|
||||
</pre>
|
||||
|
||||
Sample use:
|
||||
|
||||
window.plugins.ftpclient.get("test.txt", "ftp://username:password@ftp.server.com/test.txt;type=i", win, fail);
|
||||
|
||||
## RELEASE NOTES ##
|
||||
|
||||
### Jan 12, 2011 ###
|
||||
|
||||
* Initial release
|
||||
|
||||
## BUGS AND CONTRIBUTIONS ##
|
||||
|
||||
|
||||
## LICENSE ##
|
||||
|
||||
PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
MIT License (2008). As a recipient of PhonegGap, you may choose which
|
||||
license to receive this code under (except as noted in per-module LICENSE
|
||||
files). Some modules may not be the copyright of Nitobi. These
|
||||
modules contain explicit declarations of copyright in both the LICENSE files in
|
||||
the directories in which they reside and in the code itself. No external
|
||||
contributions are allowed under licenses which are fundamentally incompatible
|
||||
with the MIT or BSD licenses that PhoneGap is distributed under.
|
||||
|
||||
The text of the MIT and BSD licenses is reproduced below.
|
||||
|
||||
---
|
||||
|
||||
### The "New" BSD License
|
||||
|
||||
Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of Phonegap/Nitobi nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
---
|
||||
|
||||
### The MIT License
|
||||
|
||||
Copyright (c) <2010> <Nitobi Software Inc., et. al., >
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plugin
|
||||
id = "http://phonegap.com/plugins/FtpClient"
|
||||
version = "1.0"
|
||||
platform = "Android"
|
||||
min = "1.6"
|
||||
max = "">
|
||||
|
||||
<name short="FtpClient 1.0">
|
||||
The ftp client allows you to upload and download files from a FTP server.
|
||||
</name>
|
||||
|
||||
<description>
|
||||
The ftp client allows you to upload and download files from a FTP server.
|
||||
|
||||
A simple use case would be:
|
||||
|
||||
- Downloading a text file from a FTP server in order to be displayed in your application.
|
||||
- Uploading a text file to a FTP server.
|
||||
</description>
|
||||
|
||||
<author href="http://www.ibm.com/" email="simon.macdonald@gmail.com">Simon MacDonald</author>
|
||||
|
||||
<permission name="android.permission.INTERNET" />
|
||||
<permission name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<license>
|
||||
PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
MIT License (2008). As a recipient of PhonegGap, you may choose which
|
||||
license to receive this code under (except as noted in per-module LICENSE
|
||||
files). Some modules may not be the copyright of Nitobi. These
|
||||
modules contain explicit declarations of copyright in both the LICENSE files in
|
||||
the directories in which they reside and in the code itself. No external
|
||||
contributions are allowed under licenses which are fundamentally incompatible
|
||||
with the MIT or BSD licenses that PhoneGap is distributed under.
|
||||
</license>
|
||||
</plugin>
|
||||
@@ -1,93 +0,0 @@
|
||||
FtpClient
|
||||
==========
|
||||
|
||||
FtpClient is an object that allows you to upload/download files from a FTP server.
|
||||
|
||||
Properties
|
||||
----------
|
||||
|
||||
N/A
|
||||
|
||||
Methods
|
||||
-------
|
||||
|
||||
- __get__: downloads a file from a server.
|
||||
- __put__: sends a file to a server.
|
||||
|
||||
Details
|
||||
-------
|
||||
|
||||
The `FtpClient` object is a way to upload/download files to a server using the FTP protocol.
|
||||
|
||||
The first parameter is the name of the file to upload or download.
|
||||
The second parameter is the URL of the FTP server.
|
||||
The third parameter is the success callback
|
||||
The fourth parameter is the error callback [optional]
|
||||
|
||||
Supported Platforms
|
||||
-------------------
|
||||
|
||||
- Android
|
||||
|
||||
Quick Example
|
||||
------------------------------
|
||||
|
||||
var win = function() {
|
||||
alert("yay");
|
||||
}
|
||||
|
||||
var fail = function() {
|
||||
alert("boo");
|
||||
}
|
||||
|
||||
var paths = navigator.fileMgr.getRootPaths();
|
||||
var ftpClient = new FtpClient();
|
||||
ftpClient.put(paths[0]+"/putfile.txt", "ftp://username:password@server.com:21/putfile.txt;type=i", win, fail);
|
||||
ftpClient.get(paths[0]+"/getfile.txt", "ftp://username:password@server.com:21/putfile.txt", win, fail);
|
||||
|
||||
Full Example
|
||||
------------
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Contact Example</title>
|
||||
|
||||
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
|
||||
// Wait for PhoneGap to load
|
||||
//
|
||||
function onLoad() {
|
||||
document.addEventListener("deviceready", onDeviceReady, false);
|
||||
}
|
||||
|
||||
// PhoneGap is ready
|
||||
//
|
||||
function putFile() {
|
||||
var ftpClient = new FtpClient();
|
||||
ftpClient.put(paths[0]+"/putfile.txt", "ftp://username:password@server.com:21/putfile.txt;type=i", win, fail);
|
||||
}
|
||||
|
||||
function getFile() {
|
||||
var ftpClient = new FtpClient();
|
||||
ftpClient.get(paths[0]+"/getfile.txt", "ftp://username:password@server.com:21/putfile.txt", win, fail);
|
||||
}
|
||||
|
||||
function win(r) {
|
||||
alert("Yay!");
|
||||
}
|
||||
|
||||
function fail(args) {
|
||||
alert("BOO!");
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload="onLoad()">
|
||||
<h1>Example</h1>
|
||||
<a href="#" onclick="putFile();">Put Files</a>
|
||||
<a href="#" onclick="getFile();">Get Files</a>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
@@ -1,3 +0,0 @@
|
||||
lib/commons-net-2.2.jar
|
||||
src/com/phonegap/plugins/FtpClient.java
|
||||
www/ftpclient.js
|
||||
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||
* Copyright (c) 2010, IBM Corporation
|
||||
*/
|
||||
|
||||
package com.phonegap.plugins.ftpclient;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.commons.net.ftp.FTP;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.phonegap.api.PhonegapActivity;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
public class FtpClient extends Plugin {
|
||||
|
||||
private static final String LOG_TAG = "FtpClient";
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Override
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
JSONArray result = new JSONArray();
|
||||
|
||||
try {
|
||||
String filename = args.getString(0);
|
||||
URL url = new URL(args.getString(1));
|
||||
|
||||
|
||||
if (action.equals("get")) {
|
||||
get(filename, url);
|
||||
}
|
||||
else if (action.equals("put")) {
|
||||
put(filename, url);
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (JSONException e) {
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
} catch (MalformedURLException e) {
|
||||
return new PluginResult(PluginResult.Status.MALFORMED_URL_EXCEPTION);
|
||||
} catch (IOException e) {
|
||||
return new PluginResult(PluginResult.Status.IO_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads a file to a ftp server.
|
||||
* @param filename the name of the local file to send to the server
|
||||
* @param url the url of the server
|
||||
* @throws IOException
|
||||
*/
|
||||
private void put(String filename, URL url) throws IOException {
|
||||
FTPClient f = setup(url);
|
||||
|
||||
BufferedInputStream buffIn=null;
|
||||
buffIn=new BufferedInputStream(new FileInputStream(filename));
|
||||
f.storeFile(extractFileName(url), buffIn);
|
||||
buffIn.close();
|
||||
|
||||
teardown(f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads a file from a ftp server.
|
||||
* @param filename the name to store the file locally
|
||||
* @param url the url of the server
|
||||
* @throws IOException
|
||||
*/
|
||||
private void get(String filename, URL url) throws IOException {
|
||||
FTPClient f = setup(url);
|
||||
|
||||
BufferedOutputStream buffOut=null;
|
||||
buffOut=new BufferedOutputStream(new FileOutputStream(filename));
|
||||
f.retrieveFile(extractFileName(url), buffOut);
|
||||
buffOut.flush();
|
||||
buffOut.close();
|
||||
|
||||
teardown(f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the FTP connection
|
||||
* @param f the FTPClient
|
||||
* @throws IOException
|
||||
*/
|
||||
private void teardown(FTPClient f) throws IOException {
|
||||
f.logout();
|
||||
f.disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates, connects and logs into a FTP server
|
||||
* @param url of the FTP server
|
||||
* @return an instance of FTPClient
|
||||
* @throws IOException
|
||||
*/
|
||||
private FTPClient setup(URL url) throws IOException {
|
||||
FTPClient f = new FTPClient();
|
||||
f.connect(url.getHost(), extractPort(url));
|
||||
|
||||
StringTokenizer tok = new StringTokenizer(url.getUserInfo(), ":");
|
||||
f.login(tok.nextToken(), tok.nextToken());
|
||||
|
||||
f.enterLocalPassiveMode();
|
||||
f.setFileType(FTP.BINARY_FILE_TYPE);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the port of the FTP server. Returns 21 by default.
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
private int extractPort(URL url) {
|
||||
if (url.getPort() == -1) {
|
||||
return url.getDefaultPort();
|
||||
}
|
||||
else {
|
||||
return url.getPort();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the file name from the URL.
|
||||
* @param url of the ftp server, includes the file to upload/download
|
||||
* @return the filename to upload/download
|
||||
*/
|
||||
private String extractFileName(URL url) {
|
||||
String filename = url.getFile();
|
||||
if (filename.endsWith(";type=i") || filename.endsWith(";type=a")) {
|
||||
filename = filename.substring(0, filename.length() - 7);
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||
* Copyright (c) 2010, IBM Corporation
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function FtpClient() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a file to a FTP server
|
||||
*
|
||||
* @param file The file to be uploaded to the server
|
||||
* @param url The url of the ftp server
|
||||
* @param successCallback The success callback
|
||||
* @param errorCallback The error callback
|
||||
*/
|
||||
FtpClient.prototype.put = function(file, url, successCallback, errorCallback) {
|
||||
return PhoneGap.exec(successCallback, errorCallback, "FtpClient", "put", [file, url]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Download a file from a FTP server
|
||||
*
|
||||
* @param file The file to be uploaded to the server
|
||||
* @param url The url of the ftp server
|
||||
* @param successCallback The success callback
|
||||
* @param errorCallback The error callback
|
||||
*/
|
||||
FtpClient.prototype.get = function(file, url, successCallback, errorCallback) {
|
||||
return PhoneGap.exec(successCallback, errorCallback, "FtpClient", "get", [file, url]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Load FtpClient
|
||||
*/
|
||||
PhoneGap.addConstructor(function() {
|
||||
PhoneGap.addPlugin("ftpclient", new FtpClient());
|
||||
// @deprecated: No longer needed in PhoneGap 1.0. Uncomment the addService code for earlier
|
||||
// PhoneGap releases.
|
||||
// PluginManager.addService("FtpClient", "com.phonegap.plugins.ftpclient.FtpClient");
|
||||
});
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.simonmacdonald.imei;
|
||||
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import android.content.Context;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
public class IMEIPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
if (action.equals("get")) {
|
||||
TelephonyManager telephonyManager = (TelephonyManager)this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
result = telephonyManager.getDeviceId();
|
||||
}
|
||||
else {
|
||||
status = PluginResult.Status.INVALID_ACTION;
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
var IMEI = function(){};
|
||||
|
||||
IMEI.prototype.get = function(onSuccess, onFail){
|
||||
return PhoneGap.exec(onSuccess, onFail, 'IMEI', 'get', []);
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function(){
|
||||
PhoneGap.addPlugin('imei', new IMEI());
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="target-densitydpi=low-dpi; user-scalable=no" />
|
||||
<title>PhoneGap Events Example</title>
|
||||
<script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="imei.js"></script>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
|
||||
function onLoad() {
|
||||
console.log("I've been loaded");
|
||||
document.addEventListener("deviceready", onDeviceReady, true);
|
||||
}
|
||||
|
||||
function onDeviceReady() {
|
||||
console.log("We got device ready");
|
||||
window.plugins.imei.get(function(imei) {
|
||||
var imeiVal = document.getElementById('imei');
|
||||
imeiVal.innerHTML = imei;
|
||||
}, function() {
|
||||
console.log("fail");
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="onLoad();">
|
||||
<h2>IMEI</h2>
|
||||
IMEI: <span id="imei"></span><br/>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.simonmacdonald.imei;
|
||||
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import android.content.Context;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
|
||||
public class IMEIPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
if (action.equals("get")) {
|
||||
TelephonyManager telephonyManager = (TelephonyManager)this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
result = telephonyManager.getDeviceId();
|
||||
}
|
||||
else {
|
||||
status = PluginResult.Status.INVALID_ACTION;
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
var IMEI = function(){};
|
||||
|
||||
IMEI.prototype.get = function(onSuccess, onFail){
|
||||
return cordova.exec(onSuccess, onFail, 'IMEI', 'get', []);
|
||||
};
|
||||
|
||||
cordova.addConstructor(function(){
|
||||
cordova.addPlugin('imei', new IMEI());
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="target-densitydpi=low-dpi; user-scalable=no" />
|
||||
<title>PhoneGap Events Example</title>
|
||||
<script type="text/javascript" charset="utf-8" src="cordova-1.6.1.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="imei.js"></script>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
|
||||
function onLoad() {
|
||||
console.log("I've been loaded");
|
||||
document.addEventListener("deviceready", onDeviceReady, true);
|
||||
}
|
||||
|
||||
function onDeviceReady() {
|
||||
console.log("We got device ready");
|
||||
window.plugins.imei.get(function(imei) {
|
||||
var imeiVal = document.getElementById('imei');
|
||||
imeiVal.innerHTML = imei;
|
||||
}, function() {
|
||||
console.log("fail");
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="onLoad();">
|
||||
<h2>IMEI v1.5</h2>
|
||||
IMEI: <span id="imei"></span><br/>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.simonmacdonald.imei;
|
||||
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import android.content.Context;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
|
||||
public class IMEIPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
if (action.equals("get")) {
|
||||
TelephonyManager telephonyManager = (TelephonyManager)this.cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
result = telephonyManager.getDeviceId();
|
||||
}
|
||||
else {
|
||||
status = PluginResult.Status.INVALID_ACTION;
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
var IMEI = function(){};
|
||||
|
||||
IMEI.prototype.get = function(onSuccess, onFail){
|
||||
return cordova.exec(onSuccess, onFail, 'IMEI', 'get', []);
|
||||
};
|
||||
|
||||
if(!window.plugins) {
|
||||
window.plugins = {};
|
||||
}
|
||||
if (!window.plugins.imei) {
|
||||
window.plugins.imei = new IMEI();
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="target-densitydpi=low-dpi; user-scalable=no" />
|
||||
<title>PhoneGap Events Example</title>
|
||||
<script type="text/javascript" charset="utf-8" src="cordova-1.6.1.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="imei.js"></script>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
|
||||
function onLoad() {
|
||||
console.log("I've been loaded");
|
||||
document.addEventListener("deviceready", onDeviceReady, true);
|
||||
}
|
||||
|
||||
function onDeviceReady() {
|
||||
console.log("We got device ready");
|
||||
window.plugins.imei.get(function(imei) {
|
||||
var imeiVal = document.getElementById('imei');
|
||||
imeiVal.innerHTML = imei;
|
||||
}, function() {
|
||||
console.log("fail");
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="onLoad();">
|
||||
<h2>IMEI v1.5</h2>
|
||||
IMEI: <span id="imei"></span><br/>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,64 +0,0 @@
|
||||
PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
MIT License (2008). As a recipient of PhonegGap, you may choose which
|
||||
license to receive this code under (except as noted in per-module LICENSE
|
||||
files). Some modules may not be the copyright of Nitobi. These
|
||||
modules contain explicit declarations of copyright in both the LICENSE files in
|
||||
the directories in which they reside and in the code itself. No external
|
||||
contributions are allowed under licenses which are fundamentally incompatible
|
||||
with the MIT or BSD licenses that PhoneGap is distributed under.
|
||||
|
||||
The text of the MIT and BSD licenses is reproduced below.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
The "New" BSD License:
|
||||
**********************
|
||||
|
||||
Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of Phonegap/Nitobi nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
The MIT License
|
||||
*****************
|
||||
|
||||
Copyright (c) <2010> <Nitobi Software Inc., et. al., >
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plugin
|
||||
id = "http://phonegap.com/plugins/TTS"
|
||||
version = "1.0"
|
||||
platform = "Android"
|
||||
min = "1.6"
|
||||
max = "">
|
||||
|
||||
<name short="TTS 1.0">
|
||||
The TTS class that allows you to access the devices TTS services.
|
||||
</name>
|
||||
|
||||
<description>
|
||||
The TTS class that allows you to access the devices TTS services.
|
||||
|
||||
A simple use case would be:
|
||||
|
||||
- Playing text passed into the service out as synthesized speech
|
||||
</description>
|
||||
|
||||
<author href="http://www.ibm.com/" email="simon.macdonald@gmail.com">Simon MacDonald</author>
|
||||
|
||||
<license>
|
||||
PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
MIT License (2008). As a recipient of PhonegGap, you may choose which
|
||||
license to receive this code under (except as noted in per-module LICENSE
|
||||
files). Some modules may not be the copyright of Nitobi. These
|
||||
modules contain explicit declarations of copyright in both the LICENSE files in
|
||||
the directories in which they reside and in the code itself. No external
|
||||
contributions are allowed under licenses which are fundamentally incompatible
|
||||
with the MIT or BSD licenses that PhoneGap is distributed under.
|
||||
</license>
|
||||
</plugin>
|
||||
@@ -1,127 +0,0 @@
|
||||
TTS
|
||||
==========
|
||||
|
||||
The TTS class that allows you to access the devices TTS services.
|
||||
|
||||
Properties
|
||||
----------
|
||||
|
||||
N/A
|
||||
|
||||
Methods
|
||||
-------
|
||||
|
||||
- __startup__: starts the TTS service.
|
||||
- __shutdown__: stops the TTS service.
|
||||
- __speak__: speaks the specified text.
|
||||
- __silence__: plays silence for the specified number of ms.
|
||||
- __getLanguage__: gets the current TTS language.
|
||||
- __setLanguage__: sets the current TTS language.
|
||||
- __isLanguageAvailable__: finds out if TTS supports the language.
|
||||
|
||||
|
||||
Details
|
||||
-------
|
||||
|
||||
The TTS class is a way to have your application read out text in a machine generated format.
|
||||
|
||||
|
||||
|
||||
Supported Platforms
|
||||
-------------------
|
||||
|
||||
- Android
|
||||
|
||||
Quick Example
|
||||
------------------------------
|
||||
|
||||
window.plugins.tts.startup(startupWin, startupFail);
|
||||
|
||||
function startupWin(result) {
|
||||
// When result is equal to STARTED we are ready to play
|
||||
if (result == TTS.STARTED) {
|
||||
window.plugins.tts.speak("The text to speech service is ready");
|
||||
}
|
||||
}
|
||||
|
||||
function startupFail(result) {
|
||||
console.log("Startup failure = " + result);
|
||||
}
|
||||
|
||||
Full Example
|
||||
------------
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>PhoneGap Events Example</title>
|
||||
|
||||
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="tts.js"></script>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
|
||||
// Call onDeviceReady when PhoneGap is loaded.
|
||||
//
|
||||
// At this point, the document has loaded but phonegap.js has not.
|
||||
// When PhoneGap is loaded and talking with the native device,
|
||||
// it will call the event `deviceready`.
|
||||
//
|
||||
function onLoad() {
|
||||
document.addEventListener("deviceready", onDeviceReady, false);
|
||||
}
|
||||
|
||||
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
|
||||
//
|
||||
function onDeviceReady() {
|
||||
window.plugins.tts.startup(startupWin, fail);
|
||||
}
|
||||
|
||||
function startupWin(result) {
|
||||
// When result is equal to STARTED we are ready to play
|
||||
if (result == TTS.STARTED) {
|
||||
window.plugins.tts.getLanguage(win, fail);
|
||||
window.plugins.tts.speak("The text to speech service is ready");
|
||||
window.plugins.tts.isLanguageAvailable("en", function() {
|
||||
addLang("en");
|
||||
}, fail);
|
||||
window.plugins.tts.isLanguageAvailable("fr", function() {
|
||||
addLang("fr");
|
||||
}, fail);
|
||||
}
|
||||
}
|
||||
|
||||
function addLang(lang) {
|
||||
var langs = document.getElementById('langs');
|
||||
var anOption = document.createElement("OPTION")
|
||||
anOption.innerText = lang;
|
||||
anOption.Value = lang;
|
||||
langs.options.add(anOption);
|
||||
}
|
||||
|
||||
function changeLang() {
|
||||
var yourSelect = document.getElementById('langs');
|
||||
window.plugins.tts.setLanguage(yourSelect.options[yourSelect.selectedIndex].value, win, fail);
|
||||
}
|
||||
|
||||
function win(result) {
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
function fail(result) {
|
||||
console.log("Error = " + result);
|
||||
}
|
||||
|
||||
function speak() {
|
||||
window.plugins.tts.speak(document.getElementById('playMe').value);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="onLoad()">
|
||||
<h2>TTS Example</h2>
|
||||
<input id="playMe" type="text"/><br/>
|
||||
<select id="langs" onchange="changeLang()"></select>
|
||||
<a href="javascript:speak()">Speak</a><br/>
|
||||
test
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,3 +0,0 @@
|
||||
lib/commons-net-2.2.jar
|
||||
src/com/phonegap/plugins/FtpClient.java
|
||||
www/ftpclient.js
|
||||
@@ -1,210 +0,0 @@
|
||||
/*
|
||||
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2011, IBM Corporation
|
||||
*
|
||||
* Modified by Murray Macdonald (murray@workgroup.ca) on 2012/05/30 to add support for stop(), pitch(), speed() and interrupt();
|
||||
*
|
||||
*/
|
||||
|
||||
package com.phonegap.plugins.speech;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.speech.tts.TextToSpeech.OnInitListener;
|
||||
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
|
||||
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
|
||||
public class TTS extends Plugin implements OnInitListener, OnUtteranceCompletedListener {
|
||||
|
||||
private static final String LOG_TAG = "TTS";
|
||||
private static final int STOPPED = 0;
|
||||
private static final int INITIALIZING = 1;
|
||||
private static final int STARTED = 2;
|
||||
private TextToSpeech mTts = null;
|
||||
private int state = STOPPED;
|
||||
|
||||
private String startupCallbackId = "";
|
||||
|
||||
@Override
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
if (action.equals("speak")) {
|
||||
String text = args.getString(0);
|
||||
if (isReady()) {
|
||||
HashMap<String, String> map = null;
|
||||
map = new HashMap<String, String>();
|
||||
map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackId);
|
||||
mTts.speak(text, TextToSpeech.QUEUE_ADD, map);
|
||||
PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
pr.setKeepCallback(true);
|
||||
return pr;
|
||||
} else {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("message","TTS service is still initialzing.");
|
||||
error.put("code", TTS.INITIALIZING);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
} else if (action.equals("interrupt")) {
|
||||
String text = args.getString(0);
|
||||
if (isReady()) {
|
||||
HashMap<String, String> map = null;
|
||||
map = new HashMap<String, String>();
|
||||
map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackId);
|
||||
mTts.speak(text, TextToSpeech.QUEUE_FLUSH, map);
|
||||
PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
pr.setKeepCallback(true);
|
||||
return pr;
|
||||
} else {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("message","TTS service is still initialzing.");
|
||||
error.put("code", TTS.INITIALIZING);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
} else if (action.equals("stop")) {
|
||||
if (isReady()) {
|
||||
mTts.stop();
|
||||
return new PluginResult(status, result);
|
||||
} else {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("message","TTS service is still initialzing.");
|
||||
error.put("code", TTS.INITIALIZING);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
} else if (action.equals("silence")) {
|
||||
if (isReady()) {
|
||||
mTts.playSilence(args.getLong(0), TextToSpeech.QUEUE_ADD, null);
|
||||
return new PluginResult(status, result);
|
||||
} else {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("message","TTS service is still initialzing.");
|
||||
error.put("code", TTS.INITIALIZING);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
} else if (action.equals("speed")) {
|
||||
if (isReady()) {
|
||||
float speed= (float) (args.optLong(0, 100)) /(float) 100.0;
|
||||
mTts.setSpeechRate(speed);
|
||||
return new PluginResult(status, result);
|
||||
} else {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("message","TTS service is still initialzing.");
|
||||
error.put("code", TTS.INITIALIZING);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
} else if (action.equals("pitch")) {
|
||||
if (isReady()) {
|
||||
float pitch= (float) (args.optLong(0, 100)) /(float) 100.0;
|
||||
mTts.setPitch(pitch);
|
||||
return new PluginResult(status, result);
|
||||
} else {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("message","TTS service is still initialzing.");
|
||||
error.put("code", TTS.INITIALIZING);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
} else if (action.equals("startup")) {
|
||||
if (mTts == null) {
|
||||
this.startupCallbackId = callbackId;
|
||||
state = TTS.INITIALIZING;
|
||||
mTts = new TextToSpeech(ctx.getApplicationContext(), this);
|
||||
}
|
||||
PluginResult pluginResult = new PluginResult(status, TTS.INITIALIZING);
|
||||
pluginResult.setKeepCallback(true);
|
||||
return pluginResult;
|
||||
}
|
||||
else if (action.equals("shutdown")) {
|
||||
if (mTts != null) {
|
||||
mTts.shutdown();
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
else if (action.equals("getLanguage")) {
|
||||
if (mTts != null) {
|
||||
result = mTts.getLanguage().toString();
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
}
|
||||
else if (action.equals("isLanguageAvailable")) {
|
||||
if (mTts != null) {
|
||||
Locale loc = new Locale(args.getString(0));
|
||||
int available = mTts.isLanguageAvailable(loc);
|
||||
result = (available < 0) ? "false" : "true";
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
}
|
||||
else if (action.equals("setLanguage")) {
|
||||
if (mTts != null) {
|
||||
Locale loc = new Locale(args.getString(0));
|
||||
int available = mTts.setLanguage(loc);
|
||||
result = (available < 0) ? "false" : "true";
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the TTS service ready to play yet?
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private boolean isReady() {
|
||||
return (state == TTS.STARTED) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the TTS service is initialized.
|
||||
*
|
||||
* @param status
|
||||
*/
|
||||
public void onInit(int status) {
|
||||
if (status == TextToSpeech.SUCCESS) {
|
||||
state = TTS.STARTED;
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK, TTS.STARTED);
|
||||
result.setKeepCallback(false);
|
||||
this.success(result, this.startupCallbackId);
|
||||
mTts.setOnUtteranceCompletedListener(this);
|
||||
}
|
||||
else if (status == TextToSpeech.ERROR) {
|
||||
state = TTS.STOPPED;
|
||||
PluginResult result = new PluginResult(PluginResult.Status.ERROR, TTS.STOPPED);
|
||||
result.setKeepCallback(false);
|
||||
this.error(result, this.startupCallbackId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up the TTS resources
|
||||
*/
|
||||
public void onDestroy() {
|
||||
if (mTts != null) {
|
||||
mTts.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Once the utterance has completely been played call the speak's success callback
|
||||
*/
|
||||
public void onUtteranceCompleted(String utteranceId) {
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK);
|
||||
result.setKeepCallback(false);
|
||||
this.success(result, utteranceId);
|
||||
}
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2011, IBM Corporation
|
||||
*
|
||||
* Modified by Murray Macdonald (murray@workgroup.ca) on 2012/05/30 to add pitch(), speed(), stop(), and interrupt() methods.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function TTS() {
|
||||
}
|
||||
|
||||
TTS.STOPPED = 0;
|
||||
TTS.INITIALIZING = 1;
|
||||
TTS.STARTED = 2;
|
||||
|
||||
/**
|
||||
* Play the passed in text as synthesized speech
|
||||
*
|
||||
* @param {DOMString} text
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.speak = function(text, successCallback, errorCallback) {
|
||||
return PhoneGap.exec(successCallback, errorCallback, "TTS", "speak", [text]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Interrupt any existing speech, then speak the passed in text as synthesized speech
|
||||
*
|
||||
* @param {DOMString} text
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.interrupt = function(text, successCallback, errorCallback) {
|
||||
return PhoneGap.exec(successCallback, errorCallback, "TTS", "interrupt", [text]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop any queued synthesized speech
|
||||
*
|
||||
* @param {DOMString} text
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.stop= function(successCallback, errorCallback) {
|
||||
return PhoneGap.exec(successCallback, errorCallback, "TTS", "stop", []);
|
||||
};
|
||||
|
||||
/**
|
||||
* Play silence for the number of ms passed in as duration
|
||||
*
|
||||
* @param {long} duration
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.silence = function(duration, successCallback, errorCallback) {
|
||||
return PhoneGap.exec(successCallback, errorCallback, "TTS", "silence", [duration]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set speed of speech. Usable from 30 to 500. Higher values make little difference.
|
||||
*
|
||||
* @param {long} speed
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.speed = function(speed, successCallback, errorCallback) {
|
||||
return PhoneGap.exec(successCallback, errorCallback, "TTS", "speed", [speed]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set pitch of speech. Useful values are approximately 30 - 300
|
||||
*
|
||||
* @param {long} pitch
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.pitch = function(pitch, successCallback, errorCallback) {
|
||||
return PhoneGap.exec(successCallback, errorCallback, "TTS", "pitch", [pitch]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts up the TTS Service
|
||||
*
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.startup = function(successCallback, errorCallback) {
|
||||
return PhoneGap.exec(successCallback, errorCallback, "TTS", "startup", []);
|
||||
};
|
||||
|
||||
/**
|
||||
* Shuts down the TTS Service if you no longer need it.
|
||||
*
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.shutdown = function(successCallback, errorCallback) {
|
||||
return PhoneGap.exec(successCallback, errorCallback, "TTS", "shutdown", []);
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds out if the language is currently supported by the TTS service.
|
||||
*
|
||||
* @param {DOMSting} lang
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.isLanguageAvailable = function(lang, successCallback, errorCallback) {
|
||||
return PhoneGap.exec(successCallback, errorCallback, "TTS", "isLanguageAvailable", [lang]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds out the current language of the TTS service.
|
||||
*
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.getLanguage = function(successCallback, errorCallback) {
|
||||
return PhoneGap.exec(successCallback, errorCallback, "TTS", "getLanguage", []);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the language of the TTS service.
|
||||
*
|
||||
* @param {DOMString} lang
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.setLanguage = function(lang, successCallback, errorCallback) {
|
||||
return PhoneGap.exec(successCallback, errorCallback, "TTS", "setLanguage", [lang]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Load TTS
|
||||
*/
|
||||
PhoneGap.addConstructor(function() {
|
||||
PhoneGap.addPlugin("tts", new TTS());
|
||||
// @deprecated: No longer needed in PhoneGap 1.0. Uncomment the addService code for earlier
|
||||
// PhoneGap releases.
|
||||
// PluginManager.addService("TTS", "com.phonegap.plugins.speech.TTS");
|
||||
});
|
||||
@@ -1,64 +0,0 @@
|
||||
PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
MIT License (2008). As a recipient of PhonegGap, you may choose which
|
||||
license to receive this code under (except as noted in per-module LICENSE
|
||||
files). Some modules may not be the copyright of Nitobi. These
|
||||
modules contain explicit declarations of copyright in both the LICENSE files in
|
||||
the directories in which they reside and in the code itself. No external
|
||||
contributions are allowed under licenses which are fundamentally incompatible
|
||||
with the MIT or BSD licenses that PhoneGap is distributed under.
|
||||
|
||||
The text of the MIT and BSD licenses is reproduced below.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
The "New" BSD License:
|
||||
**********************
|
||||
|
||||
Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of Phonegap/Nitobi nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
The MIT License
|
||||
*****************
|
||||
|
||||
Copyright (c) <2010> <Nitobi Software Inc., et. al., >
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plugin
|
||||
id = "http://phonegap.com/plugins/TTS"
|
||||
version = "1.0"
|
||||
platform = "Android"
|
||||
min = "1.6"
|
||||
max = "">
|
||||
|
||||
<name short="TTS 1.0">
|
||||
The TTS class that allows you to access the devices TTS services.
|
||||
</name>
|
||||
|
||||
<description>
|
||||
The TTS class that allows you to access the devices TTS services.
|
||||
|
||||
A simple use case would be:
|
||||
|
||||
- Playing text passed into the service out as synthesized speech
|
||||
</description>
|
||||
|
||||
<author href="http://www.ibm.com/" email="simon.macdonald@gmail.com">Simon MacDonald</author>
|
||||
|
||||
<license>
|
||||
PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
MIT License (2008). As a recipient of PhonegGap, you may choose which
|
||||
license to receive this code under (except as noted in per-module LICENSE
|
||||
files). Some modules may not be the copyright of Nitobi. These
|
||||
modules contain explicit declarations of copyright in both the LICENSE files in
|
||||
the directories in which they reside and in the code itself. No external
|
||||
contributions are allowed under licenses which are fundamentally incompatible
|
||||
with the MIT or BSD licenses that PhoneGap is distributed under.
|
||||
</license>
|
||||
</plugin>
|
||||
@@ -1,127 +0,0 @@
|
||||
TTS
|
||||
==========
|
||||
|
||||
The TTS class that allows you to access the devices TTS services.
|
||||
|
||||
Properties
|
||||
----------
|
||||
|
||||
N/A
|
||||
|
||||
Methods
|
||||
-------
|
||||
|
||||
- __startup__: starts the TTS service.
|
||||
- __shutdown__: stops the TTS service.
|
||||
- __speak__: speaks the specified text.
|
||||
- __silence__: plays silence for the specified number of ms.
|
||||
- __getLanguage__: gets the current TTS language.
|
||||
- __setLanguage__: sets the current TTS language.
|
||||
- __isLanguageAvailable__: finds out if TTS supports the language.
|
||||
|
||||
|
||||
Details
|
||||
-------
|
||||
|
||||
The TTS class is a way to have your application read out text in a machine generated format.
|
||||
|
||||
|
||||
|
||||
Supported Platforms
|
||||
-------------------
|
||||
|
||||
- Android
|
||||
|
||||
Quick Example
|
||||
------------------------------
|
||||
|
||||
window.plugins.tts.startup(startupWin, startupFail);
|
||||
|
||||
function startupWin(result) {
|
||||
// When result is equal to STARTED we are ready to play
|
||||
if (result == TTS.STARTED) {
|
||||
window.plugins.tts.speak("The text to speech service is ready");
|
||||
}
|
||||
}
|
||||
|
||||
function startupFail(result) {
|
||||
console.log("Startup failure = " + result);
|
||||
}
|
||||
|
||||
Full Example
|
||||
------------
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>PhoneGap Events Example</title>
|
||||
|
||||
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="tts.js"></script>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
|
||||
// Call onDeviceReady when PhoneGap is loaded.
|
||||
//
|
||||
// At this point, the document has loaded but phonegap.js has not.
|
||||
// When PhoneGap is loaded and talking with the native device,
|
||||
// it will call the event `deviceready`.
|
||||
//
|
||||
function onLoad() {
|
||||
document.addEventListener("deviceready", onDeviceReady, false);
|
||||
}
|
||||
|
||||
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
|
||||
//
|
||||
function onDeviceReady() {
|
||||
window.plugins.tts.startup(startupWin, fail);
|
||||
}
|
||||
|
||||
function startupWin(result) {
|
||||
// When result is equal to STARTED we are ready to play
|
||||
if (result == TTS.STARTED) {
|
||||
window.plugins.tts.getLanguage(win, fail);
|
||||
window.plugins.tts.speak("The text to speech service is ready");
|
||||
window.plugins.tts.isLanguageAvailable("en", function() {
|
||||
addLang("en");
|
||||
}, fail);
|
||||
window.plugins.tts.isLanguageAvailable("fr", function() {
|
||||
addLang("fr");
|
||||
}, fail);
|
||||
}
|
||||
}
|
||||
|
||||
function addLang(lang) {
|
||||
var langs = document.getElementById('langs');
|
||||
var anOption = document.createElement("OPTION")
|
||||
anOption.innerText = lang;
|
||||
anOption.Value = lang;
|
||||
langs.options.add(anOption);
|
||||
}
|
||||
|
||||
function changeLang() {
|
||||
var yourSelect = document.getElementById('langs');
|
||||
window.plugins.tts.setLanguage(yourSelect.options[yourSelect.selectedIndex].value, win, fail);
|
||||
}
|
||||
|
||||
function win(result) {
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
function fail(result) {
|
||||
console.log("Error = " + result);
|
||||
}
|
||||
|
||||
function speak() {
|
||||
window.plugins.tts.speak(document.getElementById('playMe').value);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="onLoad()">
|
||||
<h2>TTS Example</h2>
|
||||
<input id="playMe" type="text"/><br/>
|
||||
<select id="langs" onchange="changeLang()"></select>
|
||||
<a href="javascript:speak()">Speak</a><br/>
|
||||
test
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,3 +0,0 @@
|
||||
lib/commons-net-2.2.jar
|
||||
src/com/phonegap/plugins/FtpClient.java
|
||||
www/ftpclient.js
|
||||
@@ -1,210 +0,0 @@
|
||||
/*
|
||||
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2011, IBM Corporation
|
||||
*
|
||||
* Modified by Murray Macdonald (murray@workgroup.ca) on 2012/05/30 to add support for stop(), pitch(), speed() and interrupt();
|
||||
*
|
||||
*/
|
||||
|
||||
package com.phonegap.plugins.speech;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.speech.tts.TextToSpeech.OnInitListener;
|
||||
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
|
||||
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
|
||||
public class TTS extends Plugin implements OnInitListener, OnUtteranceCompletedListener {
|
||||
|
||||
private static final String LOG_TAG = "TTS";
|
||||
private static final int STOPPED = 0;
|
||||
private static final int INITIALIZING = 1;
|
||||
private static final int STARTED = 2;
|
||||
private TextToSpeech mTts = null;
|
||||
private int state = STOPPED;
|
||||
|
||||
private String startupCallbackId = "";
|
||||
|
||||
@Override
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
if (action.equals("speak")) {
|
||||
String text = args.getString(0);
|
||||
if (isReady()) {
|
||||
HashMap<String, String> map = null;
|
||||
map = new HashMap<String, String>();
|
||||
map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackId);
|
||||
mTts.speak(text, TextToSpeech.QUEUE_ADD, map);
|
||||
PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
pr.setKeepCallback(true);
|
||||
return pr;
|
||||
} else {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("message","TTS service is still initialzing.");
|
||||
error.put("code", TTS.INITIALIZING);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
} else if (action.equals("interrupt")) {
|
||||
String text = args.getString(0);
|
||||
if (isReady()) {
|
||||
HashMap<String, String> map = null;
|
||||
map = new HashMap<String, String>();
|
||||
map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackId);
|
||||
mTts.speak(text, TextToSpeech.QUEUE_FLUSH, map);
|
||||
PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
pr.setKeepCallback(true);
|
||||
return pr;
|
||||
} else {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("message","TTS service is still initialzing.");
|
||||
error.put("code", TTS.INITIALIZING);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
} else if (action.equals("stop")) {
|
||||
if (isReady()) {
|
||||
mTts.stop();
|
||||
return new PluginResult(status, result);
|
||||
} else {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("message","TTS service is still initialzing.");
|
||||
error.put("code", TTS.INITIALIZING);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
} else if (action.equals("silence")) {
|
||||
if (isReady()) {
|
||||
mTts.playSilence(args.getLong(0), TextToSpeech.QUEUE_ADD, null);
|
||||
return new PluginResult(status, result);
|
||||
} else {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("message","TTS service is still initialzing.");
|
||||
error.put("code", TTS.INITIALIZING);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
} else if (action.equals("speed")) {
|
||||
if (isReady()) {
|
||||
float speed= (float) (args.optLong(0, 100)) /(float) 100.0;
|
||||
mTts.setSpeechRate(speed);
|
||||
return new PluginResult(status, result);
|
||||
} else {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("message","TTS service is still initialzing.");
|
||||
error.put("code", TTS.INITIALIZING);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
} else if (action.equals("pitch")) {
|
||||
if (isReady()) {
|
||||
float pitch= (float) (args.optLong(0, 100)) /(float) 100.0;
|
||||
mTts.setPitch(pitch);
|
||||
return new PluginResult(status, result);
|
||||
} else {
|
||||
JSONObject error = new JSONObject();
|
||||
error.put("message","TTS service is still initialzing.");
|
||||
error.put("code", TTS.INITIALIZING);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
}
|
||||
} else if (action.equals("startup")) {
|
||||
if (mTts == null) {
|
||||
this.startupCallbackId = callbackId;
|
||||
state = TTS.INITIALIZING;
|
||||
mTts = new TextToSpeech(cordova.getActivity().getApplicationContext(), this);
|
||||
}
|
||||
PluginResult pluginResult = new PluginResult(status, TTS.INITIALIZING);
|
||||
pluginResult.setKeepCallback(true);
|
||||
return pluginResult;
|
||||
}
|
||||
else if (action.equals("shutdown")) {
|
||||
if (mTts != null) {
|
||||
mTts.shutdown();
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
else if (action.equals("getLanguage")) {
|
||||
if (mTts != null) {
|
||||
result = mTts.getLanguage().toString();
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
}
|
||||
else if (action.equals("isLanguageAvailable")) {
|
||||
if (mTts != null) {
|
||||
Locale loc = new Locale(args.getString(0));
|
||||
int available = mTts.isLanguageAvailable(loc);
|
||||
result = (available < 0) ? "false" : "true";
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
}
|
||||
else if (action.equals("setLanguage")) {
|
||||
if (mTts != null) {
|
||||
Locale loc = new Locale(args.getString(0));
|
||||
int available = mTts.setLanguage(loc);
|
||||
result = (available < 0) ? "false" : "true";
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the TTS service ready to play yet?
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private boolean isReady() {
|
||||
return (state == TTS.STARTED) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the TTS service is initialized.
|
||||
*
|
||||
* @param status
|
||||
*/
|
||||
public void onInit(int status) {
|
||||
if (status == TextToSpeech.SUCCESS) {
|
||||
state = TTS.STARTED;
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK, TTS.STARTED);
|
||||
result.setKeepCallback(false);
|
||||
this.success(result, this.startupCallbackId);
|
||||
mTts.setOnUtteranceCompletedListener(this);
|
||||
}
|
||||
else if (status == TextToSpeech.ERROR) {
|
||||
state = TTS.STOPPED;
|
||||
PluginResult result = new PluginResult(PluginResult.Status.ERROR, TTS.STOPPED);
|
||||
result.setKeepCallback(false);
|
||||
this.error(result, this.startupCallbackId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up the TTS resources
|
||||
*/
|
||||
public void onDestroy() {
|
||||
if (mTts != null) {
|
||||
mTts.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Once the utterance has completely been played call the speak's success callback
|
||||
*/
|
||||
public void onUtteranceCompleted(String utteranceId) {
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK);
|
||||
result.setKeepCallback(false);
|
||||
this.success(result, utteranceId);
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
* cordova is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2011, IBM Corporation
|
||||
*/
|
||||
/*
|
||||
* cordova is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2011, IBM Corporation
|
||||
*
|
||||
* Modified by Murray Macdonald (murray@workgroup.ca) on 2012/05/30 to add pitch(), speed(), stop(), and interrupt() methods.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function TTS() {
|
||||
}
|
||||
|
||||
TTS.STOPPED = 0;
|
||||
TTS.INITIALIZING = 1;
|
||||
TTS.STARTED = 2;
|
||||
|
||||
/**
|
||||
* Play the passed in text as synthesized speech
|
||||
*
|
||||
* @param {DOMString} text
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.speak = function(text, successCallback, errorCallback) {
|
||||
return cordova.exec(successCallback, errorCallback, "TTS", "speak", [text]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Interrupt any existing speech, then speak the passed in text as synthesized speech
|
||||
*
|
||||
* @param {DOMString} text
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.interrupt = function(text, successCallback, errorCallback) {
|
||||
return cordova.exec(successCallback, errorCallback, "TTS", "interrupt", [text]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop any queued synthesized speech
|
||||
*
|
||||
* @param {DOMString} text
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.stop= function(successCallback, errorCallback) {
|
||||
return cordova.exec(successCallback, errorCallback, "TTS", "stop", []);
|
||||
};
|
||||
|
||||
/**
|
||||
* Play silence for the number of ms passed in as duration
|
||||
*
|
||||
* @param {long} duration
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.silence = function(duration, successCallback, errorCallback) {
|
||||
return cordova.exec(successCallback, errorCallback, "TTS", "silence", [duration]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set speed of speech. Usable from 30 to 500. Higher values make little difference.
|
||||
*
|
||||
* @param {long} speed
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.speed = function(speed, successCallback, errorCallback) {
|
||||
return cordova.exec(successCallback, errorCallback, "TTS", "speed", [speed]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set pitch of speech. Useful values are approximately 30 - 300
|
||||
*
|
||||
* @param {long} pitch
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.pitch = function(pitch, successCallback, errorCallback) {
|
||||
return cordova.exec(successCallback, errorCallback, "TTS", "pitch", [pitch]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts up the TTS Service
|
||||
*
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.startup = function(successCallback, errorCallback) {
|
||||
return cordova.exec(successCallback, errorCallback, "TTS", "startup", []);
|
||||
};
|
||||
|
||||
/**
|
||||
* Shuts down the TTS Service if you no longer need it.
|
||||
*
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.shutdown = function(successCallback, errorCallback) {
|
||||
return cordova.exec(successCallback, errorCallback, "TTS", "shutdown", []);
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds out if the language is currently supported by the TTS service.
|
||||
*
|
||||
* @param {DOMSting} lang
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.isLanguageAvailable = function(lang, successCallback, errorCallback) {
|
||||
return cordova.exec(successCallback, errorCallback, "TTS", "isLanguageAvailable", [lang]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds out the current language of the TTS service.
|
||||
*
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.getLanguage = function(successCallback, errorCallback) {
|
||||
return cordova.exec(successCallback, errorCallback, "TTS", "getLanguage", []);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the language of the TTS service.
|
||||
*
|
||||
* @param {DOMString} lang
|
||||
* @param {Object} successCallback
|
||||
* @param {Object} errorCallback
|
||||
*/
|
||||
TTS.prototype.setLanguage = function(lang, successCallback, errorCallback) {
|
||||
return cordova.exec(successCallback, errorCallback, "TTS", "setLanguage", [lang]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Load TTS
|
||||
*/
|
||||
|
||||
if(!window.plugins) {
|
||||
window.plugins = {};
|
||||
}
|
||||
if (!window.plugins.tts) {
|
||||
window.plugins.tts = new TTS();
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||
* Copyright (c) 2011, IBM Corporation
|
||||
*/
|
||||
|
||||
package com.phonegap.plugins.video;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
public class VideoPlayer extends Plugin {
|
||||
private static final String YOU_TUBE = "youtube.com";
|
||||
private static final String ASSETS = "file:///android_asset/";
|
||||
|
||||
@Override
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
if (action.equals("playVideo")) {
|
||||
playVideo(args.getString(0));
|
||||
}
|
||||
else {
|
||||
status = PluginResult.Status.INVALID_ACTION;
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (JSONException e) {
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
} catch (IOException e) {
|
||||
return new PluginResult(PluginResult.Status.IO_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
private void playVideo(String url) throws IOException {
|
||||
// Create URI
|
||||
Uri uri = Uri.parse(url);
|
||||
|
||||
Intent intent = null;
|
||||
// Check to see if someone is trying to play a YouTube page.
|
||||
if (url.contains(YOU_TUBE)) {
|
||||
// If we don't do it this way you don't have the option for youtube
|
||||
uri = Uri.parse("vnd.youtube:" + uri.getQueryParameter("v"));
|
||||
intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
} else if(url.contains(ASSETS)) {
|
||||
// get file path in assets folder
|
||||
String filepath = url.replace(ASSETS, "");
|
||||
// get actual filename from path as command to write to internal storage doesn't like folders
|
||||
String filename = filepath.substring(filepath.lastIndexOf("/")+1, filepath.length());
|
||||
|
||||
// Don't copy the file if it already exists
|
||||
File fp = new File(this.ctx.getContext().getFilesDir() + "/" + filename);
|
||||
if (!fp.exists()) {
|
||||
this.copy(filepath, filename);
|
||||
}
|
||||
|
||||
// change uri to be to the new file in internal storage
|
||||
uri = Uri.parse("file://" + this.ctx.getContext().getFilesDir() + "/" + filename);
|
||||
|
||||
// Display video player
|
||||
intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, "video/*");
|
||||
} else {
|
||||
// Display video player
|
||||
intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, "video/*");
|
||||
}
|
||||
|
||||
this.ctx.startActivity(intent);
|
||||
}
|
||||
|
||||
private void copy(String fileFrom, String fileTo) throws IOException {
|
||||
// get file to be copied from assets
|
||||
InputStream in = this.ctx.getAssets().open(fileFrom);
|
||||
// get file where copied too, in internal storage.
|
||||
// must be MODE_WORLD_READABLE or Android can't play it
|
||||
FileOutputStream out = this.ctx.getContext().openFileOutput(fileTo, Context.MODE_WORLD_READABLE);
|
||||
|
||||
// Transfer bytes from in to out
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0)
|
||||
out.write(buf, 0, len);
|
||||
in.close();
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||
* Copyright (c) 2011, IBM Corporation
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function VideoPlayer() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts the video player intent
|
||||
*
|
||||
* @param url The url to play
|
||||
*/
|
||||
VideoPlayer.prototype.play = function(url) {
|
||||
PhoneGap.exec(null, null, "VideoPlayer", "playVideo", [url]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Load VideoPlayer
|
||||
*/
|
||||
PhoneGap.addConstructor(function() {
|
||||
PhoneGap.addPlugin("videoPlayer", new VideoPlayer());
|
||||
});
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||
* Copyright (c) 2011, IBM Corporation
|
||||
*/
|
||||
|
||||
package com.phonegap.plugins.video;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
|
||||
public class VideoPlayer extends Plugin {
|
||||
private static final String YOU_TUBE = "youtube.com";
|
||||
private static final String ASSETS = "file:///android_asset/";
|
||||
|
||||
@Override
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
if (action.equals("playVideo")) {
|
||||
playVideo(args.getString(0));
|
||||
}
|
||||
else {
|
||||
status = PluginResult.Status.INVALID_ACTION;
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (JSONException e) {
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
} catch (IOException e) {
|
||||
return new PluginResult(PluginResult.Status.IO_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
private void playVideo(String url) throws IOException {
|
||||
// Create URI
|
||||
Uri uri = Uri.parse(url);
|
||||
|
||||
Intent intent = null;
|
||||
// Check to see if someone is trying to play a YouTube page.
|
||||
if (url.contains(YOU_TUBE)) {
|
||||
// If we don't do it this way you don't have the option for youtube
|
||||
uri = Uri.parse("vnd.youtube:" + uri.getQueryParameter("v"));
|
||||
intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
} else if(url.contains(ASSETS)) {
|
||||
// get file path in assets folder
|
||||
String filepath = url.replace(ASSETS, "");
|
||||
// get actual filename from path as command to write to internal storage doesn't like folders
|
||||
String filename = filepath.substring(filepath.lastIndexOf("/")+1, filepath.length());
|
||||
|
||||
// Don't copy the file if it already exists
|
||||
File fp = new File(this.cordova.getActivity().getFilesDir() + "/" + filename);
|
||||
if (!fp.exists()) {
|
||||
this.copy(filepath, filename);
|
||||
}
|
||||
|
||||
// change uri to be to the new file in internal storage
|
||||
uri = Uri.parse("file://" + this.cordova.getActivity().getFilesDir() + "/" + filename);
|
||||
|
||||
// Display video player
|
||||
intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, "video/*");
|
||||
} else {
|
||||
// Display video player
|
||||
intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, "video/*");
|
||||
}
|
||||
|
||||
this.cordova.getActivity().startActivity(intent);
|
||||
}
|
||||
|
||||
private void copy(String fileFrom, String fileTo) throws IOException {
|
||||
// get file to be copied from assets
|
||||
InputStream in = this.cordova.getActivity().getAssets().open(fileFrom);
|
||||
// get file where copied too, in internal storage.
|
||||
// must be MODE_WORLD_READABLE or Android can't play it
|
||||
FileOutputStream out = this.cordova.getActivity().openFileOutput(fileTo, Context.MODE_WORLD_READABLE);
|
||||
|
||||
// Transfer bytes from in to out
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0)
|
||||
out.write(buf, 0, len);
|
||||
in.close();
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||
* Copyright (c) 2011, IBM Corporation
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function VideoPlayer() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts the video player intent
|
||||
*
|
||||
* @param url The url to play
|
||||
*/
|
||||
VideoPlayer.prototype.play = function(url) {
|
||||
cordova.exec(null, null, "VideoPlayer", "playVideo", [url]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Load VideoPlayer
|
||||
*/
|
||||
|
||||
if(!window.plugins) {
|
||||
window.plugins = {};
|
||||
}
|
||||
if (!window.plugins.videoPlayer) {
|
||||
window.plugins.videoPlayer = new VideoPlayer();
|
||||
}
|
||||
Reference in New Issue
Block a user