Massive Merge Commit of DEATH TO SPACES

This commit is contained in:
Joe Bowser 2012-06-06 14:35:45 -07:00
commit 81195db87d
55 changed files with 882 additions and 951 deletions

View File

@ -1,33 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>Cordova</name> <name>Cordova</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name> <name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
</projectDescription> </projectDescription>

View File

@ -18,16 +18,16 @@
under the License. under the License.
--> -->
<cordova> <cordova>
<!-- <!--
access elements control the Android whitelist. access elements control the Android whitelist.
Domains are assumed blocked unless set otherwise Domains are assumed blocked unless set otherwise
--> -->
<access origin="http://127.0.0.1*"/> <!-- allow local pages --> <access origin="http://127.0.0.1*"/> <!-- allow local pages -->
<!-- <access origin="https://example.com" /> allow any secure requests to example.com --> <!-- <access origin="https://example.com" /> allow any secure requests to example.com -->
<!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www --> <!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
<!-- <access origin=".*"/> Allow all domains, suggested development use only --> <!-- <access origin=".*"/> Allow all domains, suggested development use only -->
<log level="DEBUG"/> <log level="DEBUG"/>
<preference name="useBrowserHistory" value="false" /> <preference name="useBrowserHistory" value="false" />

View File

@ -23,31 +23,31 @@ import org.json.JSONObject;
public class PluginResult extends org.apache.cordova.api.PluginResult { public class PluginResult extends org.apache.cordova.api.PluginResult {
public PluginResult(Status status) { public PluginResult(Status status) {
super(status); super(status);
} }
public PluginResult(Status status, String message) { public PluginResult(Status status, String message) {
super(status, message);
}
public PluginResult(Status status, JSONArray message) {
super(status, message); super(status, message);
} }
public PluginResult(Status status, JSONObject message) { public PluginResult(Status status, JSONArray message) {
super(status, message); super(status, message);
} }
public PluginResult(Status status, int i) { public PluginResult(Status status, JSONObject message) {
super(status, message);
}
public PluginResult(Status status, int i) {
super(status, i); super(status, i);
} }
public PluginResult(Status status, float f) { public PluginResult(Status status, float f) {
super(status, f); super(status, f);
} }
public PluginResult(Status status, boolean b) { public PluginResult(Status status, boolean b) {
super(status, b); super(status, b);
} }
} }

View File

@ -18,12 +18,7 @@
*/ */
package org.apache.cordova; package org.apache.cordova;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.cordova.api.CordovaInterface; import org.apache.cordova.api.CordovaInterface;
import org.apache.cordova.api.Plugin; import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult; import org.apache.cordova.api.PluginResult;
@ -35,8 +30,6 @@ import android.hardware.Sensor;
import android.hardware.SensorEvent; import android.hardware.SensorEvent;
import android.hardware.SensorEventListener; import android.hardware.SensorEventListener;
import android.hardware.SensorManager; import android.hardware.SensorManager;
import android.location.Location;
import android.util.Log;
import android.content.Context; import android.content.Context;
/** /**
@ -132,11 +125,11 @@ public class AccelListener extends Plugin implements SensorEventListener {
* Start listening for acceleration sensor. * Start listening for acceleration sensor.
* *
* @return status of listener * @return status of listener
*/ */
private int start() { private int start() {
// If already starting or running, then just return // If already starting or running, then just return
if ((this.status == AccelListener.RUNNING) || (this.status == AccelListener.STARTING)) { if ((this.status == AccelListener.RUNNING) || (this.status == AccelListener.STARTING)) {
return this.status; return this.status;
} }
this.setStatus(AccelListener.STARTING); this.setStatus(AccelListener.STARTING);
@ -258,7 +251,6 @@ public class AccelListener extends Plugin implements SensorEventListener {
private void setStatus(int status) { private void setStatus(int status) {
this.status = status; this.status = status;
} }
private JSONObject getAccelerationJSON() { private JSONObject getAccelerationJSON() {
JSONObject r = new JSONObject(); JSONObject r = new JSONObject();
try { try {

View File

@ -102,7 +102,7 @@ public class App extends Plugin {
* @throws JSONException * @throws JSONException
*/ */
public void loadUrl(String url, JSONObject props) throws JSONException { public void loadUrl(String url, JSONObject props) throws JSONException {
LOG.d("App", "App.loadUrl(" + url + "," + props + ")"); LOG.d("App", "App.loadUrl("+url+","+props+")");
int wait = 0; int wait = 0;
boolean openExternal = false; boolean openExternal = false;
boolean clearHistory = false; boolean clearHistory = false;
@ -128,13 +128,13 @@ public class App extends Plugin {
} }
else if (value.getClass().equals(String.class)) { else if (value.getClass().equals(String.class)) {
params.put(key, (String) value); params.put(key, (String)value);
} }
else if (value.getClass().equals(Boolean.class)) { else if (value.getClass().equals(Boolean.class)) {
params.put(key, (Boolean) value); params.put(key, (Boolean)value);
} }
else if (value.getClass().equals(Integer.class)) { else if (value.getClass().equals(Integer.class)) {
params.put(key, (Integer) value); params.put(key, (Integer)value);
} }
} }
} }
@ -144,7 +144,7 @@ public class App extends Plugin {
if (wait > 0) { if (wait > 0) {
try { try {
synchronized (this) { synchronized(this) {
this.wait(wait); this.wait(wait);
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {

View File

@ -22,7 +22,6 @@ import android.content.Context;
import android.media.AudioManager; import android.media.AudioManager;
import java.util.ArrayList; import java.util.ArrayList;
//import org.apache.cordova.api.LOG;
import org.apache.cordova.api.Plugin; import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult; import org.apache.cordova.api.PluginResult;
import org.json.JSONArray; import org.json.JSONArray;
@ -56,7 +55,6 @@ public class AudioHandler extends Plugin {
/** /**
* Executes the request and returns PluginResult. * Executes the request and returns PluginResult.
*
* @param action The action to execute. * @param action The action to execute.
* @param args JSONArry of arguments for the plugin. * @param args JSONArry of arguments for the plugin.
* @param callbackId The callback id used when calling back into JavaScript. * @param callbackId The callback id used when calling back into JavaScript.
@ -85,11 +83,11 @@ public class AudioHandler extends Plugin {
else if (action.equals("stopPlayingAudio")) { else if (action.equals("stopPlayingAudio")) {
this.stopPlayingAudio(args.getString(0)); this.stopPlayingAudio(args.getString(0));
} else if (action.equals("setVolume")) { } else if (action.equals("setVolume")) {
try { try {
this.setVolume(args.getString(0), Float.parseFloat(args.getString(1))); this.setVolume(args.getString(0), Float.parseFloat(args.getString(1)));
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
//no-op //no-op
} }
} else if (action.equals("getCurrentPositionAudio")) { } else if (action.equals("getCurrentPositionAudio")) {
float f = this.getCurrentPositionAudio(args.getString(0)); float f = this.getCurrentPositionAudio(args.getString(0));
return new PluginResult(status, f); return new PluginResult(status, f);
@ -111,7 +109,6 @@ public class AudioHandler extends Plugin {
/** /**
* Identifies if action to be executed returns a value and should be run synchronously. * Identifies if action to be executed returns a value and should be run synchronously.
*
* @param action The action to execute * @param action The action to execute
* @return T=returns value * @return T=returns value
*/ */
@ -177,7 +174,6 @@ public class AudioHandler extends Plugin {
/** /**
* Release the audio player instance to save memory. * Release the audio player instance to save memory.
*
* @param id The id of the audio player * @param id The id of the audio player
*/ */
private boolean release(String id) { private boolean release(String id) {
@ -192,7 +188,6 @@ public class AudioHandler extends Plugin {
/** /**
* Start recording and save the specified file. * Start recording and save the specified file.
*
* @param id The id of the audio player * @param id The id of the audio player
* @param file The name of the file * @param file The name of the file
*/ */
@ -208,7 +203,6 @@ public class AudioHandler extends Plugin {
/** /**
* Stop recording and save to the file specified when recording started. * Stop recording and save to the file specified when recording started.
*
* @param id The id of the audio player * @param id The id of the audio player
*/ */
public void stopRecordingAudio(String id) { public void stopRecordingAudio(String id) {
@ -221,7 +215,6 @@ public class AudioHandler extends Plugin {
/** /**
* Start or resume playing audio file. * Start or resume playing audio file.
*
* @param id The id of the audio player * @param id The id of the audio player
* @param file The name of the audio file. * @param file The name of the audio file.
*/ */
@ -236,8 +229,6 @@ public class AudioHandler extends Plugin {
/** /**
* Seek to a location. * Seek to a location.
*
*
* @param id The id of the audio player * @param id The id of the audio player
* @param miliseconds int: number of milliseconds to skip 1000 = 1 second * @param miliseconds int: number of milliseconds to skip 1000 = 1 second
*/ */
@ -250,7 +241,6 @@ public class AudioHandler extends Plugin {
/** /**
* Pause playing. * Pause playing.
*
* @param id The id of the audio player * @param id The id of the audio player
*/ */
public void pausePlayingAudio(String id) { public void pausePlayingAudio(String id) {
@ -262,7 +252,6 @@ public class AudioHandler extends Plugin {
/** /**
* Stop playing the audio file. * Stop playing the audio file.
*
* @param id The id of the audio player * @param id The id of the audio player
*/ */
public void stopPlayingAudio(String id) { public void stopPlayingAudio(String id) {
@ -276,7 +265,6 @@ public class AudioHandler extends Plugin {
/** /**
* Get current position of playback. * Get current position of playback.
*
* @param id The id of the audio player * @param id The id of the audio player
* @return position in msec * @return position in msec
*/ */
@ -290,7 +278,6 @@ public class AudioHandler extends Plugin {
/** /**
* Get the duration of the audio file. * Get the duration of the audio file.
*
* @param id The id of the audio player * @param id The id of the audio player
* @param file The name of the audio file. * @param file The name of the audio file.
* @return The duration in msec. * @return The duration in msec.

View File

@ -74,7 +74,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
private String tempFile = null; // Temporary recording file name private String tempFile = null; // Temporary recording file name
private MediaPlayer mPlayer = null; // Audio player object private MediaPlayer mPlayer = null; // Audio player object
private boolean prepareOnly = false; private boolean prepareOnly = false;
/** /**
* Constructor. * Constructor.
@ -88,7 +88,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
this.tempFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmprecording.mp3"; this.tempFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmprecording.mp3";
} else { } else {
this.tempFile = "/data/data/" + handler.ctx.getPackageName() + "/cache/tmprecording.mp3"; this.tempFile = "/data/data/" + handler.ctx.getActivity().getPackageName() + "/cache/tmprecording.mp3";
} }
} }
@ -96,7 +96,6 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
* Destroy player and stop audio playing or recording. * Destroy player and stop audio playing or recording.
*/ */
public void destroy() { public void destroy() {
// Stop any play or record // Stop any play or record
if (this.mPlayer != null) { if (this.mPlayer != null) {
if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) { if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) {
@ -123,7 +122,6 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
Log.d(LOG_TAG, "AudioPlayer Error: Can't record in play mode."); Log.d(LOG_TAG, "AudioPlayer Error: Can't record in play mode.");
this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
} }
// Make sure we're not already recording // Make sure we're not already recording
else if (this.recorder == null) { else if (this.recorder == null) {
this.audioFile = file; this.audioFile = file;
@ -162,7 +160,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
f.renameTo(new File(Environment.getExternalStorageDirectory().getAbsolutePath() f.renameTo(new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator + file)); + File.separator + file));
} else { } else {
f.renameTo(new File("/data/data/" + handler.ctx.getPackageName() + "/cache/" + file)); f.renameTo(new File("/data/data/" + handler.ctx.getActivity().getPackageName() + "/cache/" + file));
} }
} }
@ -172,13 +170,14 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
*/ */
public void stopRecording() { public void stopRecording() {
if (this.recorder != null) { if (this.recorder != null) {
try { try{
if (this.state == MEDIA_RUNNING) { if (this.state == MEDIA_RUNNING) {
this.recorder.stop(); this.recorder.stop();
this.setState(MEDIA_STOPPED); this.setState(MEDIA_STOPPED);
} }
this.moveFile(this.audioFile); this.moveFile(this.audioFile);
} catch (Exception e) { }
catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -104,15 +104,14 @@ public class CallbackServer implements Runnable {
/** /**
* Init callback server and start XHR if running local app. * Init callback server and start XHR if running local app.
* *
* If Cordova app is loaded from file://, then we can use XHR * If Cordova app is loaded from file://, then we can use XHR
* otherwise we have to use polling due to cross-domain security restrictions. * otherwise we have to use polling due to cross-domain security restrictions.
* *
* @param url The URL of the Cordova app being loaded * @param url The URL of the Cordova app being loaded
*/ */
@SuppressWarnings("deprecation")
public void init(String url) { public void init(String url) {
//Log.d(LOG_TAG, "CallbackServer.start("+url+")"); //System.out.println("CallbackServer.start("+url+")");
this.active = false; this.active = false;
this.empty = true; this.empty = true;
this.port = 0; this.port = 0;
@ -145,7 +144,6 @@ public class CallbackServer implements Runnable {
/** /**
* Return if polling is being used instead of XHR. * Return if polling is being used instead of XHR.
*
* @return * @return
*/ */
public boolean usePolling() { public boolean usePolling() {
@ -154,7 +152,6 @@ public class CallbackServer implements Runnable {
/** /**
* Get the port that this server is running on. * Get the port that this server is running on.
*
* @return * @return
*/ */
public int getPort() { public int getPort() {
@ -163,7 +160,6 @@ public class CallbackServer implements Runnable {
/** /**
* Get the security token that this server requires when calling getJavascript(). * Get the security token that this server requires when calling getJavascript().
*
* @return * @return
*/ */
public String getToken() { public String getToken() {

View File

@ -305,7 +305,6 @@ public class CameraLauncher extends Plugin {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
// If CAMERA // If CAMERA
if (srcType == CAMERA) { if (srcType == CAMERA) {
// If image available // If image available
@ -415,7 +414,7 @@ public class CameraLauncher extends Plugin {
matrix.setRotate(rotate); matrix.setRotate(rotate);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
} }
bitmap = scaleBitmap(bitmap); bitmap = scaleBitmap(bitmap);
this.processPicture(bitmap); this.processPicture(bitmap);
bitmap.recycle(); bitmap.recycle();
bitmap = null; bitmap = null;

View File

@ -54,7 +54,7 @@ public class Capture extends Plugin {
// private static final int CAPTURE_APPLICATION_BUSY = 1; // private static final int CAPTURE_APPLICATION_BUSY = 1;
// private static final int CAPTURE_INVALID_ARGUMENT = 2; // private static final int CAPTURE_INVALID_ARGUMENT = 2;
private static final int CAPTURE_NO_MEDIA_FILES = 3; private static final int CAPTURE_NO_MEDIA_FILES = 3;
// private static final int CAPTURE_NOT_SUPPORTED = 20; private static final int CAPTURE_NOT_SUPPORTED = 20;
private String callbackId; // The ID of the callback to be invoked with our result private String callbackId; // The ID of the callback to be invoked with our result
private long limit; // the number of pics/vids/clips to take private long limit; // the number of pics/vids/clips to take

View File

@ -25,10 +25,7 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -88,39 +85,39 @@ public class ContactAccessorSdk5 extends ContactAccessor {
*/ */
private static final Map<String, String> dbMap = new HashMap<String, String>(); private static final Map<String, String> dbMap = new HashMap<String, String>();
static { static {
dbMap.put("id", ContactsContract.Data.CONTACT_ID); dbMap.put("id", ContactsContract.Data.CONTACT_ID);
dbMap.put("displayName", ContactsContract.Contacts.DISPLAY_NAME); dbMap.put("displayName", ContactsContract.Contacts.DISPLAY_NAME);
dbMap.put("name", ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME); dbMap.put("name", ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME);
dbMap.put("name.formatted", ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME); dbMap.put("name.formatted", ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME);
dbMap.put("name.familyName", ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME); dbMap.put("name.familyName", ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME);
dbMap.put("name.givenName", ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME); dbMap.put("name.givenName", ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME);
dbMap.put("name.middleName", ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME); dbMap.put("name.middleName", ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME);
dbMap.put("name.honorificPrefix", ContactsContract.CommonDataKinds.StructuredName.PREFIX); dbMap.put("name.honorificPrefix", ContactsContract.CommonDataKinds.StructuredName.PREFIX);
dbMap.put("name.honorificSuffix", ContactsContract.CommonDataKinds.StructuredName.SUFFIX); dbMap.put("name.honorificSuffix", ContactsContract.CommonDataKinds.StructuredName.SUFFIX);
dbMap.put("nickname", ContactsContract.CommonDataKinds.Nickname.NAME); dbMap.put("nickname", ContactsContract.CommonDataKinds.Nickname.NAME);
dbMap.put("phoneNumbers", ContactsContract.CommonDataKinds.Phone.NUMBER); dbMap.put("phoneNumbers", ContactsContract.CommonDataKinds.Phone.NUMBER);
dbMap.put("phoneNumbers.value", ContactsContract.CommonDataKinds.Phone.NUMBER); dbMap.put("phoneNumbers.value", ContactsContract.CommonDataKinds.Phone.NUMBER);
dbMap.put("emails", ContactsContract.CommonDataKinds.Email.DATA); dbMap.put("emails", ContactsContract.CommonDataKinds.Email.DATA);
dbMap.put("emails.value", ContactsContract.CommonDataKinds.Email.DATA); dbMap.put("emails.value", ContactsContract.CommonDataKinds.Email.DATA);
dbMap.put("addresses", ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS); dbMap.put("addresses", ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS);
dbMap.put("addresses.formatted", ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS); dbMap.put("addresses.formatted", ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS);
dbMap.put("addresses.streetAddress", ContactsContract.CommonDataKinds.StructuredPostal.STREET); dbMap.put("addresses.streetAddress", ContactsContract.CommonDataKinds.StructuredPostal.STREET);
dbMap.put("addresses.locality", ContactsContract.CommonDataKinds.StructuredPostal.CITY); dbMap.put("addresses.locality", ContactsContract.CommonDataKinds.StructuredPostal.CITY);
dbMap.put("addresses.region", ContactsContract.CommonDataKinds.StructuredPostal.REGION); dbMap.put("addresses.region", ContactsContract.CommonDataKinds.StructuredPostal.REGION);
dbMap.put("addresses.postalCode", ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE); dbMap.put("addresses.postalCode", ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE);
dbMap.put("addresses.country", ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY); dbMap.put("addresses.country", ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY);
dbMap.put("ims", ContactsContract.CommonDataKinds.Im.DATA); dbMap.put("ims", ContactsContract.CommonDataKinds.Im.DATA);
dbMap.put("ims.value", ContactsContract.CommonDataKinds.Im.DATA); dbMap.put("ims.value", ContactsContract.CommonDataKinds.Im.DATA);
dbMap.put("organizations", ContactsContract.CommonDataKinds.Organization.COMPANY); dbMap.put("organizations", ContactsContract.CommonDataKinds.Organization.COMPANY);
dbMap.put("organizations.name", ContactsContract.CommonDataKinds.Organization.COMPANY); dbMap.put("organizations.name", ContactsContract.CommonDataKinds.Organization.COMPANY);
dbMap.put("organizations.department", ContactsContract.CommonDataKinds.Organization.DEPARTMENT); dbMap.put("organizations.department", ContactsContract.CommonDataKinds.Organization.DEPARTMENT);
dbMap.put("organizations.title", ContactsContract.CommonDataKinds.Organization.TITLE); dbMap.put("organizations.title", ContactsContract.CommonDataKinds.Organization.TITLE);
dbMap.put("birthday", ContactsContract.CommonDataKinds.Event.START_DATE); dbMap.put("birthday", ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE);
dbMap.put("note", ContactsContract.CommonDataKinds.Note.NOTE); dbMap.put("note", ContactsContract.CommonDataKinds.Note.NOTE);
dbMap.put("photos.value", ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE); dbMap.put("photos.value", ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
//dbMap.put("categories.value", null); //dbMap.put("categories.value", null);
dbMap.put("urls", ContactsContract.CommonDataKinds.Website.URL); dbMap.put("urls", ContactsContract.CommonDataKinds.Website.URL);
dbMap.put("urls.value", ContactsContract.CommonDataKinds.Website.URL); dbMap.put("urls.value", ContactsContract.CommonDataKinds.Website.URL);
} }
/** /**
@ -539,71 +536,67 @@ public class ContactAccessorSdk5 extends ContactAccessor {
where.add("(" + dbMap.get(key) + " LIKE ? )"); where.add("(" + dbMap.get(key) + " LIKE ? )");
whereArgs.add(searchTerm); whereArgs.add(searchTerm);
} }
else if (key.startsWith("name")) { else if (key.startsWith("name")) {
where.add("(" + dbMap.get(key) + " LIKE ? AND " where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ ContactsContract.Data.MIMETYPE + " = ? )"); + ContactsContract.Data.MIMETYPE + " = ? )");
whereArgs.add(searchTerm); whereArgs.add(searchTerm);
whereArgs.add(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); whereArgs.add(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
} }
else if (key.startsWith("nickname")) { else if (key.startsWith("nickname")) {
where.add("(" + dbMap.get(key) + " LIKE ? AND " where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ ContactsContract.Data.MIMETYPE + " = ? )"); + ContactsContract.Data.MIMETYPE + " = ? )");
whereArgs.add(searchTerm); whereArgs.add(searchTerm);
whereArgs.add(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE); whereArgs.add(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE);
} }
else if (key.startsWith("phoneNumbers")) { else if (key.startsWith("phoneNumbers")) {
where.add("(" + dbMap.get(key) + " LIKE ? AND " where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ ContactsContract.Data.MIMETYPE + " = ? )"); + ContactsContract.Data.MIMETYPE + " = ? )");
whereArgs.add(searchTerm); whereArgs.add(searchTerm);
whereArgs.add(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); whereArgs.add(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
} }
else if (key.startsWith("emails")) { else if (key.startsWith("emails")) {
where.add("(" + dbMap.get(key) + " LIKE ? AND " where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ ContactsContract.Data.MIMETYPE + " = ? )"); + ContactsContract.Data.MIMETYPE + " = ? )");
whereArgs.add(searchTerm); whereArgs.add(searchTerm);
whereArgs.add(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); whereArgs.add(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
} }
else if (key.startsWith("addresses")) { else if (key.startsWith("addresses")) {
where.add("(" + dbMap.get(key) + " LIKE ? AND " where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ ContactsContract.Data.MIMETYPE + " = ? )"); + ContactsContract.Data.MIMETYPE + " = ? )");
whereArgs.add(searchTerm); whereArgs.add(searchTerm);
whereArgs.add(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE); whereArgs.add(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE);
} }
else if (key.startsWith("ims")) { else if (key.startsWith("ims")) {
where.add("(" + dbMap.get(key) + " LIKE ? AND " where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ ContactsContract.Data.MIMETYPE + " = ? )"); + ContactsContract.Data.MIMETYPE + " = ? )");
whereArgs.add(searchTerm); whereArgs.add(searchTerm);
whereArgs.add(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE); whereArgs.add(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
} }
else if (key.startsWith("organizations")) { else if (key.startsWith("organizations")) {
where.add("(" + dbMap.get(key) + " LIKE ? AND " where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ ContactsContract.Data.MIMETYPE + " = ? )"); + ContactsContract.Data.MIMETYPE + " = ? )");
whereArgs.add(searchTerm); whereArgs.add(searchTerm);
whereArgs.add(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE); whereArgs.add(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE);
} }
else if (key.startsWith("birthday")) { // else if (key.startsWith("birthday")) {
try { // where.add("(" + dbMap.get(key) + " LIKE ? AND "
SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM dd, yyyy"); // + ContactsContract.Data.MIMETYPE + " = ? )");
Date searchDate = format.parse(searchTerm.substring(1, searchTerm.length()-1)); // }
// Have to subtract one from the month as JavaScript's January is 01 else if (key.startsWith("note")) {
// while Java's January is 00. where.add("(" + dbMap.get(key) + " LIKE ? AND "
searchDate.setMonth(searchDate.getMonth()-1); + ContactsContract.Data.MIMETYPE + " = ? )");
SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd"); whereArgs.add(searchTerm);
whereArgs.add(ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE);
where.add("(" + dbMap.get(key) + " = ? AND " }
+ ContactsContract.Data.MIMETYPE + " = ? )"); else if (key.startsWith("urls")) {
whereArgs.add(newFormat.format(searchDate)); where.add("(" + dbMap.get(key) + " LIKE ? AND "
whereArgs.add(ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE); + ContactsContract.Data.MIMETYPE + " = ? )");
whereArgs.add(searchTerm);
whereArgs.add(ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE);
}
} }
catch (ParseException e) { } catch (JSONException e) {
Log.d(LOG_TAG, "Bad romance format"); Log.e(LOG_TAG, e.getMessage(), e);
}
}
else if (key.startsWith("note")) {
where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ ContactsContract.Data.MIMETYPE + " = ? )");
whereArgs.add(searchTerm);
whereArgs.add(ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE);
} }
// Creating the where string // Creating the where string
@ -1135,47 +1128,18 @@ public class ContactAccessorSdk5 extends ContactAccessor {
Log.d(LOG_TAG, "Could not get emails"); Log.d(LOG_TAG, "Could not get emails");
} }
// Modify note // Modify note
String note = getJsonString(contact, "note"); String note = getJsonString(contact, "note");
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(ContactsContract.Data.CONTACT_ID + "=? AND " + .withSelection(ContactsContract.Data.CONTACT_ID + "=? AND " +
ContactsContract.Data.MIMETYPE + "=?", ContactsContract.Data.MIMETYPE + "=?",
new String[]{id,ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE}) new String[] { id, ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE })
.withValue(ContactsContract.CommonDataKinds.Note.NOTE, note) .withValue(ContactsContract.CommonDataKinds.Note.NOTE, note)
.build()); .build());
// Modify nickname // Modify nickname
String nickname = getJsonString(contact, "nickname"); String nickname = getJsonString(contact, "nickname");
if (nickname != null) { if (nickname != null) {
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(ContactsContract.Data.CONTACT_ID + "=? AND " +
ContactsContract.Data.MIMETYPE + "=?",
new String[]{id,ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE})
.withValue(ContactsContract.CommonDataKinds.Nickname.NAME, nickname)
.build());
}
// Modify urls
JSONArray websites = null;
try {
websites = contact.getJSONArray("urls");
if (websites != null) {
for (int i=0; i<websites.length(); i++) {
JSONObject website = (JSONObject)websites.get(i);
String websiteId = getJsonString(website, "id");
// This is a new website so do a DB insert
if (websiteId==null) {
ContentValues contentValues = new ContentValues();
contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, rawId);
contentValues.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE);
contentValues.put(ContactsContract.CommonDataKinds.Website.DATA, getJsonString(website, "value"));
contentValues.put(ContactsContract.CommonDataKinds.Website.TYPE, getContactType(getJsonString(website, "type")));
ops.add(ContentProviderOperation.newInsert(
ContactsContract.Data.CONTENT_URI).withValues(contentValues).build());
}
// This is an existing website so do a DB update
else {
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(ContactsContract.Data.CONTACT_ID + "=? AND " + .withSelection(ContactsContract.Data.CONTACT_ID + "=? AND " +
ContactsContract.Data.MIMETYPE + "=?", ContactsContract.Data.MIMETYPE + "=?",
@ -1963,3 +1927,4 @@ public class ContactAccessorSdk5 extends ContactAccessor {
return stringType; return stringType;
} }
} }

View File

@ -45,15 +45,15 @@ public class CordovaLocationListener implements LocationListener {
private String TAG = "[Cordova Location Listener]"; private String TAG = "[Cordova Location Listener]";
public CordovaLocationListener(LocationManager manager, GeoBroker broker, String tag) { public CordovaLocationListener(LocationManager manager, GeoBroker broker, String tag) {
this.locationManager = manager; this.locationManager = manager;
this.owner = broker; this.owner = broker;
this.TAG = tag; this.TAG = tag;
} }
protected void fail(int code, String message) { protected void fail(int code, String message) {
for (String callbackId: this.callbacks) for (String callbackId: this.callbacks)
{ {
this.owner.fail(code, message, callbackId); this.owner.fail(code, message, callbackId);
} }
this.callbacks.clear(); this.callbacks.clear();
@ -65,9 +65,9 @@ public class CordovaLocationListener implements LocationListener {
} }
private void win(Location loc) { private void win(Location loc) {
for (String callbackId: this.callbacks) for (String callbackId: this.callbacks)
{ {
this.owner.win(loc, callbackId); this.owner.win(loc, callbackId);
} }
this.callbacks.clear(); this.callbacks.clear();
@ -82,117 +82,117 @@ public class CordovaLocationListener implements LocationListener {
* Location Listener Methods * Location Listener Methods
*/ */
/** /**
* Called when the provider is disabled by the user. * Called when the provider is disabled by the user.
* *
* @param provider * @param provider
*/ */
public void onProviderDisabled(String provider) { public void onProviderDisabled(String provider) {
Log.d(TAG, "Location provider '" + provider + "' disabled."); Log.d(TAG, "Location provider '" + provider + "' disabled.");
this.fail(POSITION_UNAVAILABLE, "GPS provider disabled."); this.fail(POSITION_UNAVAILABLE, "GPS provider disabled.");
} }
/** /**
* Called when the provider is enabled by the user. * Called when the provider is enabled by the user.
* *
* @param provider * @param provider
*/ */
public void onProviderEnabled(String provider) { public void onProviderEnabled(String provider) {
Log.d(TAG, "Location provider "+ provider + " has been enabled"); Log.d(TAG, "Location provider "+ provider + " has been enabled");
} }
/** /**
* Called when the provider status changes. This method is called when a * Called when the provider status changes. This method is called when a
* provider is unable to fetch a location or if the provider has recently * provider is unable to fetch a location or if the provider has recently
* become available after a period of unavailability. * become available after a period of unavailability.
* *
* @param provider * @param provider
* @param status * @param status
* @param extras * @param extras
*/ */
public void onStatusChanged(String provider, int status, Bundle extras) { public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d(TAG, "The status of the provider " + provider + " has changed"); Log.d(TAG, "The status of the provider " + provider + " has changed");
if (status == 0) { if (status == 0) {
Log.d(TAG, provider + " is OUT OF SERVICE"); Log.d(TAG, provider + " is OUT OF SERVICE");
this.fail(CordovaLocationListener.POSITION_UNAVAILABLE, "Provider " + provider + " is out of service."); this.fail(CordovaLocationListener.POSITION_UNAVAILABLE, "Provider " + provider + " is out of service.");
} }
else if (status == 1) { else if (status == 1) {
Log.d(TAG, provider + " is TEMPORARILY_UNAVAILABLE"); Log.d(TAG, provider + " is TEMPORARILY_UNAVAILABLE");
} }
else { else {
Log.d(TAG, provider + " is AVAILABLE"); Log.d(TAG, provider + " is AVAILABLE");
} }
} }
/** /**
* Called when the location has changed. * Called when the location has changed.
* *
* @param location * @param location
*/ */
public void onLocationChanged(Location location) { public void onLocationChanged(Location location) {
Log.d(TAG, "The location has been updated!"); Log.d(TAG, "The location has been updated!");
this.win(location); this.win(location);
} }
// PUBLIC // PUBLIC
public int size() { public int size() {
return this.watches.size() + this.callbacks.size(); return this.watches.size() + this.callbacks.size();
} }
public void addWatch(String timerId, String callbackId) { public void addWatch(String timerId, String callbackId) {
this.watches.put(timerId, callbackId); this.watches.put(timerId, callbackId);
if (this.size() == 1) { if (this.size() == 1) {
this.start(); this.start();
} }
} }
public void addCallback(String callbackId) { public void addCallback(String callbackId) {
this.callbacks.add(callbackId); this.callbacks.add(callbackId);
if (this.size() == 1) { if (this.size() == 1) {
this.start(); this.start();
} }
} }
public void clearWatch(String timerId) { public void clearWatch(String timerId) {
if (this.watches.containsKey(timerId)) { if (this.watches.containsKey(timerId)) {
this.watches.remove(timerId); this.watches.remove(timerId);
} }
if (this.size() == 0) { if (this.size() == 0) {
this.stop(); this.stop();
} }
} }
/** /**
* Destroy listener. * Destroy listener.
*/ */
public void destroy() { public void destroy() {
this.stop(); this.stop();
} }
// LOCAL // LOCAL
/** /**
* Start requesting location updates. * Start requesting location updates.
* *
* @param interval * @param interval
*/ */
protected void start() { protected void start() {
if (!this.running) { if (!this.running) {
if (this.locationManager.getProvider(LocationManager.NETWORK_PROVIDER) != null) { if (this.locationManager.getProvider(LocationManager.NETWORK_PROVIDER) != null) {
this.running = true; this.running = true;
this.locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 10, this); this.locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 10, this);
} else { } else {
this.fail(CordovaLocationListener.POSITION_UNAVAILABLE, "Network provider is not available."); this.fail(CordovaLocationListener.POSITION_UNAVAILABLE, "Network provider is not available.");
} }
} }
} }
/** /**
* Stop receiving location updates. * Stop receiving location updates.
*/ */
private void stop() { private void stop() {
if (this.running) { if (this.running) {
this.locationManager.removeUpdates(this); this.locationManager.removeUpdates(this);
this.running = false; this.running = false;
} }
} }
} }

View File

@ -37,7 +37,6 @@ public class DirectoryManager {
/** /**
* Determine if a file or directory exists. * Determine if a file or directory exists.
*
* @param name The name of the file to check. * @param name The name of the file to check.
* @return T=exists, F=not found * @return T=exists, F=not found
*/ */
@ -122,7 +121,7 @@ public class DirectoryManager {
* @param file2 Remaining file path * @param file2 Remaining file path
* @return File object * @return File object
*/ */
private static File constructFilePaths(String file1, String file2) { private static File constructFilePaths (String file1, String file2) {
File newPath; File newPath;
if (file2.startsWith(file1)) { if (file2.startsWith(file1)) {
newPath = new File(file2); newPath = new File(file2);

View File

@ -173,6 +173,9 @@ public class DroidGap extends Activity implements CordovaInterface {
protected int splashscreen = 0; protected int splashscreen = 0;
protected int splashscreenTime = 0; protected int splashscreenTime = 0;
// LoadUrl timeout value in msec (default of 20 sec)
protected int loadUrlTimeoutValue = 20000;
// Keep app running when pause is received. (default = true) // Keep app running when pause is received. (default = true)
// If true, then the JavaScript and native code continue to run in the background // If true, then the JavaScript and native code continue to run in the background
// when another application (activity) is started. // when another application (activity) is started.
@ -723,7 +726,6 @@ public class DroidGap extends Activity implements CordovaInterface {
* @param message * @param message
*/ */
public void sendJavascript(String statement) { public void sendJavascript(String statement) {
//We need to check for the null case on the Kindle Fire because it changes the width and height on load
if (this.appView != null && this.appView.callbackServer != null) { if (this.appView != null && this.appView.callbackServer != null) {
this.appView.callbackServer.sendJavascript(statement); this.appView.callbackServer.sendJavascript(statement);
} }

View File

@ -42,7 +42,6 @@ import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Environment; import android.os.Environment;
import android.provider.MediaStore; import android.provider.MediaStore;
//import android.util.Log;
import android.webkit.MimeTypeMap; import android.webkit.MimeTypeMap;
//import android.app.Activity; //import android.app.Activity;

View File

@ -26,25 +26,25 @@ import android.location.LocationManager;
* *
*/ */
public class GPSListener extends CordovaLocationListener { public class GPSListener extends CordovaLocationListener {
public GPSListener(LocationManager locationManager, GeoBroker m) { public GPSListener(LocationManager locationManager, GeoBroker m) {
super(locationManager, m, "[Cordova GPSListener]"); super(locationManager, m, "[Cordova GPSListener]");
} }
/** /**
* Start requesting location updates. * Start requesting location updates.
* *
* @param interval * @param interval
*/ */
@Override @Override
protected void start() { protected void start() {
if (!this.running) { if (!this.running) {
if (this.locationManager.getProvider(LocationManager.GPS_PROVIDER) != null) { if (this.locationManager.getProvider(LocationManager.GPS_PROVIDER) != null) {
this.running = true; this.running = true;
this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, this); this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, this);
} else { } else {
this.fail(CordovaLocationListener.POSITION_UNAVAILABLE, "GPS provider is not available."); this.fail(CordovaLocationListener.POSITION_UNAVAILABLE, "GPS provider is not available.");
} }
} }
} }
} }

View File

@ -58,10 +58,7 @@ public class HttpHandler {
HttpGet httpget = new HttpGet(url); HttpGet httpget = new HttpGet(url);
HttpResponse response = httpclient.execute(httpget); HttpResponse response = httpclient.execute(httpget);
entity = response.getEntity(); entity = response.getEntity();
} catch (Exception e) { } catch (Exception e) { e.printStackTrace(); return null; }
e.printStackTrace();
return null;
}
return entity; return entity;
} }
@ -76,7 +73,7 @@ public class HttpHandler {
byte buff[] = new byte[1024]; byte buff[] = new byte[1024];
FileOutputStream out = FileOutputStream out =
new FileOutputStream(FilePath); new FileOutputStream(FilePath);
do { do {
int numread = in.read(buff); int numread = in.read(buff);
if (numread <= 0) if (numread <= 0)
break; break;

View File

@ -26,7 +26,7 @@ import android.location.LocationManager;
* *
*/ */
public class NetworkListener extends CordovaLocationListener { public class NetworkListener extends CordovaLocationListener {
public NetworkListener(LocationManager locationManager, GeoBroker m) { public NetworkListener(LocationManager locationManager, GeoBroker m) {
super(locationManager, m, "[Cordova NetworkListener]"); super(locationManager, m, "[Cordova NetworkListener]");
} }
} }

View File

@ -18,9 +18,6 @@
*/ */
package org.apache.cordova; package org.apache.cordova;
//import java.lang.reflect.Field;
//import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
public class StandAlone extends DroidGap { public class StandAlone extends DroidGap {

View File

@ -37,203 +37,203 @@ import android.database.sqlite.*;
*/ */
public class Storage extends Plugin { public class Storage extends Plugin {
// Data Definition Language // Data Definition Language
private static final String ALTER = "alter"; private static final String ALTER = "alter";
private static final String CREATE = "create"; private static final String CREATE = "create";
private static final String DROP = "drop"; private static final String DROP = "drop";
private static final String TRUNCATE = "truncate"; private static final String TRUNCATE = "truncate";
SQLiteDatabase myDb = null; // Database object SQLiteDatabase myDb = null; // Database object
String path = null; // Database path String path = null; // Database path
String dbName = null; // Database name String dbName = null; // Database name
/** /**
* Constructor. * Constructor.
*/ */
public Storage() { public Storage() {
} }
/** /**
* Executes the request and returns PluginResult. * Executes the request and returns PluginResult.
* *
* @param action * @param action
* The action to execute. * The action to execute.
* @param args * @param args
* JSONArry of arguments for the plugin. * JSONArry of arguments for the plugin.
* @param callbackId * @param callbackId
* The callback id used when calling back into JavaScript. * The callback id used when calling back into JavaScript.
* @return A PluginResult object with a status and message. * @return A PluginResult object with a status and message.
*/ */
public PluginResult execute(String action, JSONArray args, String callbackId) { public PluginResult execute(String action, JSONArray args, String callbackId) {
PluginResult.Status status = PluginResult.Status.OK; PluginResult.Status status = PluginResult.Status.OK;
String result = ""; String result = "";
try { try {
if (action.equals("openDatabase")) { if (action.equals("openDatabase")) {
this.openDatabase(args.getString(0), args.getString(1), this.openDatabase(args.getString(0), args.getString(1),
args.getString(2), args.getLong(3)); args.getString(2), args.getLong(3));
} else if (action.equals("executeSql")) { } else if (action.equals("executeSql")) {
String[] s = null; String[] s = null;
if (args.isNull(1)) { if (args.isNull(1)) {
s = new String[0]; s = new String[0];
} else { } else {
JSONArray a = args.getJSONArray(1); JSONArray a = args.getJSONArray(1);
int len = a.length(); int len = a.length();
s = new String[len]; s = new String[len];
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
s[i] = a.getString(i); s[i] = a.getString(i);
} }
} }
this.executeSql(args.getString(0), s, args.getString(2)); this.executeSql(args.getString(0), s, args.getString(2));
} }
return new PluginResult(status, result); return new PluginResult(status, result);
} catch (JSONException e) { } catch (JSONException e) {
return new PluginResult(PluginResult.Status.JSON_EXCEPTION); return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
} }
} }
/** /**
* Identifies if action to be executed returns a value and should be run * Identifies if action to be executed returns a value and should be run
* synchronously. * synchronously.
* *
* @param action * @param action
* The action to execute * The action to execute
* @return T=returns value * @return T=returns value
*/ */
public boolean isSynch(String action) { public boolean isSynch(String action) {
return true; return true;
} }
/** /**
* Clean up and close database. * Clean up and close database.
*/ */
@Override @Override
public void onDestroy() { public void onDestroy() {
if (this.myDb != null) { if (this.myDb != null) {
this.myDb.close(); this.myDb.close();
this.myDb = null; this.myDb = null;
} }
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// LOCAL METHODS // LOCAL METHODS
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Open database. * Open database.
* *
* @param db * @param db
* The name of the database * The name of the database
* @param version * @param version
* The version * The version
* @param display_name * @param display_name
* The display name * The display name
* @param size * @param size
* The size in bytes * The size in bytes
*/ */
public void openDatabase(String db, String version, String display_name, public void openDatabase(String db, String version, String display_name,
long size) { long size) {
// If database is open, then close it // If database is open, then close it
if (this.myDb != null) { if (this.myDb != null) {
this.myDb.close(); this.myDb.close();
} }
// If no database path, generate from application package // If no database path, generate from application package
if (this.path == null) { if (this.path == null) {
this.path = this.ctx.getActivity().getDir("database", Context.MODE_PRIVATE).getPath(); this.path = this.ctx.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
} }
this.dbName = this.path + File.pathSeparator + db + ".db"; this.dbName = this.path + File.pathSeparator + db + ".db";
this.myDb = SQLiteDatabase.openOrCreateDatabase(this.dbName, null); this.myDb = SQLiteDatabase.openOrCreateDatabase(this.dbName, null);
} }
/** /**
* Execute SQL statement. * Execute SQL statement.
* *
* @param query * @param query
* The SQL query * The SQL query
* @param params * @param params
* Parameters for the query * Parameters for the query
* @param tx_id * @param tx_id
* Transaction id * Transaction id
*/ */
public void executeSql(String query, String[] params, String tx_id) { public void executeSql(String query, String[] params, String tx_id) {
try { try {
if (isDDL(query)) { if (isDDL(query)) {
this.myDb.execSQL(query); this.myDb.execSQL(query);
this.sendJavascript("cordova.require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', '');"); this.sendJavascript("cordova.require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', '');");
} }
else { else {
Cursor myCursor = this.myDb.rawQuery(query, params); Cursor myCursor = this.myDb.rawQuery(query, params);
this.processResults(myCursor, tx_id); this.processResults(myCursor, tx_id);
myCursor.close(); myCursor.close();
} }
} }
catch (SQLiteException ex) { catch (SQLiteException ex) {
ex.printStackTrace(); ex.printStackTrace();
System.out.println("Storage.executeSql(): Error=" + ex.getMessage()); System.out.println("Storage.executeSql(): Error=" + ex.getMessage());
// Send error message back to JavaScript // Send error message back to JavaScript
this.sendJavascript("cordova.require('cordova/plugin/android/storage').failQuery('" + ex.getMessage() + "','" + tx_id + "');"); this.sendJavascript("cordova.require('cordova/plugin/android/storage').failQuery('" + ex.getMessage() + "','" + tx_id + "');");
} }
} }
/** /**
* Checks to see the the query is a Data Definintion command * Checks to see the the query is a Data Definintion command
* *
* @param query to be executed * @param query to be executed
* @return true if it is a DDL command, false otherwise * @return true if it is a DDL command, false otherwise
*/ */
private boolean isDDL(String query) { private boolean isDDL(String query) {
String cmd = query.toLowerCase(); String cmd = query.toLowerCase();
if (cmd.startsWith(DROP) || cmd.startsWith(CREATE) || cmd.startsWith(ALTER) || cmd.startsWith(TRUNCATE)) { if (cmd.startsWith(DROP) || cmd.startsWith(CREATE) || cmd.startsWith(ALTER) || cmd.startsWith(TRUNCATE)) {
return true; return true;
} }
return false; return false;
} }
/** /**
* Process query results. * Process query results.
* *
* @param cur * @param cur
* Cursor into query results * Cursor into query results
* @param tx_id * @param tx_id
* Transaction id * Transaction id
*/ */
public void processResults(Cursor cur, String tx_id) { public void processResults(Cursor cur, String tx_id) {
String result = "[]"; String result = "[]";
// If query result has rows // If query result has rows
if (cur.moveToFirst()) { if (cur.moveToFirst()) {
JSONArray fullresult = new JSONArray(); JSONArray fullresult = new JSONArray();
String key = ""; String key = "";
String value = ""; String value = "";
int colCount = cur.getColumnCount(); int colCount = cur.getColumnCount();
// Build up JSON result object for each row // Build up JSON result object for each row
do { do {
JSONObject row = new JSONObject(); JSONObject row = new JSONObject();
try { try {
for (int i = 0; i < colCount; ++i) { for (int i = 0; i < colCount; ++i) {
key = cur.getColumnName(i); key = cur.getColumnName(i);
value = cur.getString(i); value = cur.getString(i);
row.put(key, value); row.put(key, value);
} }
fullresult.put(row); fullresult.put(row);
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
} while (cur.moveToNext()); } while (cur.moveToNext());
result = fullresult.toString(); result = fullresult.toString();
} }
// Let JavaScript know that there are no more rows // Let JavaScript know that there are no more rows
this.sendJavascript("cordova.require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', " + result + ");"); this.sendJavascript("cordova.require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', " + result + ");");
} }
} }

View File

@ -21,13 +21,12 @@ package org.apache.cordova.api;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
//import android.util.Log;
public class PluginResult { public class PluginResult {
private final int status; private final int status;
private final String message; private final String message;
private boolean keepCallback = false; private boolean keepCallback = false;
public PluginResult(Status status) { public PluginResult(Status status) {
this.status = status.ordinal(); this.status = status.ordinal();
this.message = "'" + PluginResult.StatusMessages[this.status] + "'"; this.message = "'" + PluginResult.StatusMessages[this.status] + "'";

View File

@ -21,8 +21,8 @@ package org.apache.cordova.file;
public class EncodingException extends Exception { public class EncodingException extends Exception {
public EncodingException(String message) { public EncodingException(String message) {
super(message); super(message);
} }
} }

View File

@ -21,8 +21,8 @@ package org.apache.cordova.file;
public class FileExistsException extends Exception { public class FileExistsException extends Exception {
public FileExistsException(String msg) { public FileExistsException(String msg) {
super(msg); super(msg);
} }
} }

View File

@ -22,8 +22,8 @@ package org.apache.cordova.file;
public class InvalidModificationException extends Exception { public class InvalidModificationException extends Exception {
public InvalidModificationException(String message) { public InvalidModificationException(String message) {
super(message); super(message);
} }
} }

View File

@ -21,8 +21,8 @@ package org.apache.cordova.file;
public class NoModificationAllowedException extends Exception { public class NoModificationAllowedException extends Exception {
public NoModificationAllowedException(String message) { public NoModificationAllowedException(String message) {
super(message); super(message);
} }
} }

View File

@ -22,8 +22,8 @@ package org.apache.cordova.file;
public class TypeMismatchException extends Exception { public class TypeMismatchException extends Exception {
public TypeMismatchException(String message) { public TypeMismatchException(String message) {
super(message); super(message);
} }
} }