2009-11-10 09:45:02 +08:00
|
|
|
package com.phonegap;
|
2009-10-01 06:34:28 +08:00
|
|
|
|
2010-09-07 02:13:09 +08:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
2010-09-08 02:59:54 +08:00
|
|
|
import com.phonegap.api.Plugin;
|
|
|
|
import com.phonegap.api.PluginResult;
|
2010-09-07 02:13:09 +08:00
|
|
|
|
2009-11-04 08:51:40 +08:00
|
|
|
import android.util.Log;
|
|
|
|
import android.webkit.WebView;
|
2010-09-07 02:13:09 +08:00
|
|
|
import android.content.Intent;
|
2009-10-01 06:34:28 +08:00
|
|
|
|
2010-09-08 02:59:54 +08:00
|
|
|
public class ContactManager implements Plugin {
|
2009-11-03 07:43:09 +08:00
|
|
|
|
2010-09-11 03:09:40 +08:00
|
|
|
private static ContactAccessor contactAccessor;
|
2010-09-07 02:13:09 +08:00
|
|
|
WebView webView; // WebView object
|
|
|
|
DroidGap ctx; // DroidGap object
|
|
|
|
|
2009-11-04 08:51:40 +08:00
|
|
|
private static final String LOG_TAG = "Contact Query";
|
2010-09-07 02:13:09 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
public ContactManager() {
|
2009-10-10 01:23:21 +08:00
|
|
|
}
|
2010-06-05 04:32:00 +08:00
|
|
|
|
2010-09-07 02:13:09 +08:00
|
|
|
/**
|
|
|
|
* Sets the context of the Command. This can then be used to do things like
|
|
|
|
* get file paths associated with the Activity.
|
|
|
|
*
|
|
|
|
* @param ctx The context of the main Activity.
|
|
|
|
*/
|
|
|
|
public void setContext(DroidGap ctx) {
|
|
|
|
this.ctx = ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the main View of the application, this is the WebView within which
|
|
|
|
* a PhoneGap app runs.
|
|
|
|
*
|
|
|
|
* @param webView The PhoneGap WebView
|
|
|
|
*/
|
|
|
|
public void setView(WebView webView) {
|
|
|
|
this.webView = webView;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the request and returns CommandResult.
|
|
|
|
*
|
|
|
|
* @param action The command to execute.
|
|
|
|
* @param args JSONArry of arguments for the command.
|
|
|
|
* @return A CommandResult object with a status and message.
|
|
|
|
*/
|
2010-09-08 02:59:54 +08:00
|
|
|
public PluginResult execute(String action, JSONArray args) {
|
2010-09-11 03:09:40 +08:00
|
|
|
if (contactAccessor == null) {
|
|
|
|
contactAccessor = ContactAccessor.getInstance(webView, ctx);
|
|
|
|
}
|
2010-09-08 02:59:54 +08:00
|
|
|
PluginResult.Status status = PluginResult.Status.OK;
|
2010-09-07 02:13:09 +08:00
|
|
|
String result = "";
|
|
|
|
|
|
|
|
try {
|
2010-09-11 03:09:40 +08:00
|
|
|
if (action.equals("search")) {
|
2010-09-25 01:22:46 +08:00
|
|
|
contactAccessor.search(args.getJSONArray(0), args.getJSONObject(1));
|
|
|
|
}
|
|
|
|
else if (action.equals("create")) {
|
|
|
|
// TODO Coming soon!
|
2010-09-07 02:13:09 +08:00
|
|
|
}
|
2010-09-25 01:22:46 +08:00
|
|
|
else if (action.equals("save")) {
|
|
|
|
// TODO Coming soon!
|
|
|
|
}
|
|
|
|
else if (action.equals("remove")) {
|
|
|
|
// TODO Coming soon!
|
2010-09-07 02:13:09 +08:00
|
|
|
}
|
2010-09-08 02:59:54 +08:00
|
|
|
return new PluginResult(status, result);
|
2010-09-07 02:13:09 +08:00
|
|
|
} catch (JSONException e) {
|
2010-09-25 01:22:46 +08:00
|
|
|
Log.e(LOG_TAG, e.getMessage(), e);
|
2010-09-08 02:59:54 +08:00
|
|
|
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
2010-09-07 02:13:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-11 00:34:06 +08:00
|
|
|
/**
|
2010-09-14 00:01:44 +08:00
|
|
|
* Identifies if action to be executed returns a value and should be run synchronously.
|
2010-09-11 00:34:06 +08:00
|
|
|
*
|
|
|
|
* @param action The action to execute
|
|
|
|
* @return T=returns value
|
|
|
|
*/
|
2010-09-14 00:01:44 +08:00
|
|
|
public boolean isSynch(String action) {
|
2010-09-11 00:34:06 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-07 02:13:09 +08:00
|
|
|
/**
|
|
|
|
* Called when the system is about to start resuming a previous activity.
|
|
|
|
*/
|
|
|
|
public void onPause() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the activity will start interacting with the user.
|
|
|
|
*/
|
|
|
|
public void onResume() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by AccelBroker when listener is to be shut down.
|
|
|
|
* Stop listener.
|
|
|
|
*/
|
|
|
|
public void onDestroy() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when an activity you launched exits, giving you the requestCode you started it with,
|
|
|
|
* the resultCode it returned, and any additional data from it.
|
|
|
|
*
|
|
|
|
* @param requestCode The request code originally supplied to startActivityForResult(),
|
|
|
|
* allowing you to identify who this result came from.
|
|
|
|
* @param resultCode The integer result code returned by the child activity through its setResult().
|
|
|
|
* @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
|
|
|
|
*/
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
|
|
}
|
2009-10-01 06:34:28 +08:00
|
|
|
}
|