spacing fixes, null check in getPhoneType in contacts, returning error integers instead of objects in contacts

This commit is contained in:
Fil Maj 2012-03-15 12:03:20 -07:00
parent df691518e3
commit 692a59a692
2 changed files with 118 additions and 128 deletions

View File

@ -1649,71 +1649,73 @@ public class ContactAccessorSdk5 extends ContactAccessor {
*/
private int getPhoneType(String string) {
int type = ContactsContract.CommonDataKinds.Phone.TYPE_OTHER;
if ("home".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_HOME;
}
else if ("mobile".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE;
}
else if ("work".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_WORK;
}
else if ("work fax".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK;
}
else if ("home fax".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME;
}
else if ("fax".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK;
}
else if ("pager".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_PAGER;
}
else if ("other".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_OTHER;
}
else if ("car".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_CAR;
}
else if ("company main".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_COMPANY_MAIN;
}
else if ("isdn".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_ISDN;
}
else if ("main".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_MAIN;
}
else if ("other fax".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_OTHER_FAX;
}
else if ("radio".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_RADIO;
}
else if ("telex".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_TELEX;
}
else if ("work mobile".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_WORK_MOBILE;
}
else if ("work pager".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_WORK_PAGER;
}
else if ("assistant".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_ASSISTANT;
}
else if ("mms".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_MMS;
}
else if ("callback".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_CALLBACK;
}
else if ("tty ttd".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_TTY_TDD;
}
else if ("custom".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM;
if (string != null) {
if ("home".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_HOME;
}
else if ("mobile".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE;
}
else if ("work".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_WORK;
}
else if ("work fax".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK;
}
else if ("home fax".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME;
}
else if ("fax".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK;
}
else if ("pager".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_PAGER;
}
else if ("other".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_OTHER;
}
else if ("car".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_CAR;
}
else if ("company main".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_COMPANY_MAIN;
}
else if ("isdn".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_ISDN;
}
else if ("main".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_MAIN;
}
else if ("other fax".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_OTHER_FAX;
}
else if ("radio".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_RADIO;
}
else if ("telex".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_TELEX;
}
else if ("work mobile".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_WORK_MOBILE;
}
else if ("work pager".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_WORK_PAGER;
}
else if ("assistant".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_ASSISTANT;
}
else if ("mms".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_MMS;
}
else if ("callback".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_CALLBACK;
}
else if ("tty ttd".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_TTY_TDD;
}
else if ("custom".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM;
}
}
return type;
}

View File

@ -26,52 +26,42 @@ import org.json.JSONObject;
import android.util.Log;
public class ContactManager extends Plugin {
private ContactAccessor contactAccessor;
private static final String LOG_TAG = "Contact Query";
private static final String LOG_TAG = "Contact Query";
public static final int UNKNOWN_ERROR = 0;
public static final int INVALID_ARGUMENT_ERROR = 1;
public static final int TIMEOUT_ERROR = 2;
public static final int PENDING_OPERATION_ERROR = 3;
public static final int IO_ERROR = 4;
public static final int NOT_SUPPORTED_ERROR = 5;
public static final int PERMISSION_DENIED_ERROR = 20;
public static final int UNKNOWN_ERROR = 0;
public static final int INVALID_ARGUMENT_ERROR = 1;
public static final int TIMEOUT_ERROR = 2;
public static final int PENDING_OPERATION_ERROR = 3;
public static final int IO_ERROR = 4;
public static final int NOT_SUPPORTED_ERROR = 5;
public static final int PERMISSION_DENIED_ERROR = 20;
/**
* Constructor.
*/
public ContactManager() {
}
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackId The callback id used when calling back into JavaScript.
* @return A PluginResult object with a status and message.
*/
public PluginResult execute(String action, JSONArray args, String callbackId) {
/**
* Constructor.
*/
public ContactManager() {
}
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackId The callback id used when calling back into JavaScript.
* @return A PluginResult object with a status and message.
*/
public PluginResult execute(String action, JSONArray args, String callbackId) {
PluginResult.Status status = PluginResult.Status.OK;
String result = "";
String result = "";
/**
* Check to see if we are on an Android 1.X device. If we are return an error as we
* do not support this as of Cordova 1.0.
*/
if (android.os.Build.VERSION.RELEASE.startsWith("1.")) {
JSONObject res = null;
try {
res = new JSONObject();
res.put("code", NOT_SUPPORTED_ERROR);
res.put("message", "Contacts are not supported in Android 1.X devices");
} catch (JSONException e) {
// This should never happen
Log.e(LOG_TAG, e.getMessage(), e);
}
return new PluginResult(PluginResult.Status.ERROR, res);
return new PluginResult(PluginResult.Status.ERROR, ContactManager.NOT_SUPPORTED_ERROR);
}
/**
@ -81,33 +71,31 @@ public class ContactManager extends Plugin {
if (this.contactAccessor == null) {
this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx.getContext());
}
try {
if (action.equals("search")) {
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
return new PluginResult(status, res);
}
else if (action.equals("save")) {
String id = contactAccessor.save(args.getJSONObject(0));
if (id != null) {
JSONObject res = contactAccessor.getContactById(id);
if (res != null) {
return new PluginResult(status, res);
}
try {
if (action.equals("search")) {
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
return new PluginResult(status, res);
}
else if (action.equals("save")) {
String id = contactAccessor.save(args.getJSONObject(0));
if (id != null) {
JSONObject res = contactAccessor.getContactById(id);
if (res != null) {
return new PluginResult(status, res);
}
}
}
else if (action.equals("remove")) {
if (contactAccessor.remove(args.getString(0))) {
return new PluginResult(status, result);
}
}
// If we get to this point an error has occurred
return new PluginResult(PluginResult.Status.ERROR, ContactManager.UNKNOWN_ERROR);
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e);
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
else if (action.equals("remove")) {
if (contactAccessor.remove(args.getString(0))) {
return new PluginResult(status, result);
}
}
// If we get to this point an error has occurred
JSONObject r = new JSONObject();
r.put("code", UNKNOWN_ERROR);
return new PluginResult(PluginResult.Status.ERROR, r);
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e);
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
}