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) { private int getPhoneType(String string) {
int type = ContactsContract.CommonDataKinds.Phone.TYPE_OTHER; int type = ContactsContract.CommonDataKinds.Phone.TYPE_OTHER;
if ("home".equals(string.toLowerCase())) { if (string != null) {
return ContactsContract.CommonDataKinds.Phone.TYPE_HOME; 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 ("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".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 ("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 ("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 ("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 ("pager".equals(string.toLowerCase())) {
} return ContactsContract.CommonDataKinds.Phone.TYPE_PAGER;
else if ("other".equals(string.toLowerCase())) { }
return ContactsContract.CommonDataKinds.Phone.TYPE_OTHER; 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 ("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 ("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 ("isdn".equals(string.toLowerCase())) {
} return ContactsContract.CommonDataKinds.Phone.TYPE_ISDN;
else if ("main".equals(string.toLowerCase())) { }
return ContactsContract.CommonDataKinds.Phone.TYPE_MAIN; 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 ("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 ("radio".equals(string.toLowerCase())) {
} return ContactsContract.CommonDataKinds.Phone.TYPE_RADIO;
else if ("telex".equals(string.toLowerCase())) { }
return ContactsContract.CommonDataKinds.Phone.TYPE_TELEX; 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 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 ("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 ("assistant".equals(string.toLowerCase())) {
} return ContactsContract.CommonDataKinds.Phone.TYPE_ASSISTANT;
else if ("mms".equals(string.toLowerCase())) { }
return ContactsContract.CommonDataKinds.Phone.TYPE_MMS; 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 ("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 ("tty ttd".equals(string.toLowerCase())) {
} return ContactsContract.CommonDataKinds.Phone.TYPE_TTY_TDD;
else if ("custom".equals(string.toLowerCase())) { }
return ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM; else if ("custom".equals(string.toLowerCase())) {
return ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM;
}
} }
return type; return type;
} }

View File

@ -28,32 +28,31 @@ import android.util.Log;
public class ContactManager extends Plugin { public class ContactManager extends Plugin {
private ContactAccessor contactAccessor; 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 UNKNOWN_ERROR = 0;
public static final int INVALID_ARGUMENT_ERROR = 1; public static final int INVALID_ARGUMENT_ERROR = 1;
public static final int TIMEOUT_ERROR = 2; public static final int TIMEOUT_ERROR = 2;
public static final int PENDING_OPERATION_ERROR = 3; public static final int PENDING_OPERATION_ERROR = 3;
public static final int IO_ERROR = 4; public static final int IO_ERROR = 4;
public static final int NOT_SUPPORTED_ERROR = 5; public static final int NOT_SUPPORTED_ERROR = 5;
public static final int PERMISSION_DENIED_ERROR = 20; public static final int PERMISSION_DENIED_ERROR = 20;
/**
* Constructor.
*/
public ContactManager() {
}
/** /**
* Constructor. * Executes the request and returns PluginResult.
*/ *
public ContactManager() { * @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.
* Executes the request and returns PluginResult. */
* public PluginResult execute(String action, JSONArray args, String callbackId) {
* @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; PluginResult.Status status = PluginResult.Status.OK;
String result = ""; String result = "";
@ -62,16 +61,7 @@ public class ContactManager extends Plugin {
* do not support this as of Cordova 1.0. * do not support this as of Cordova 1.0.
*/ */
if (android.os.Build.VERSION.RELEASE.startsWith("1.")) { if (android.os.Build.VERSION.RELEASE.startsWith("1.")) {
JSONObject res = null; return new PluginResult(PluginResult.Status.ERROR, ContactManager.NOT_SUPPORTED_ERROR);
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);
} }
/** /**
@ -82,32 +72,30 @@ public class ContactManager extends Plugin {
this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx.getContext()); this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx.getContext());
} }
try { try {
if (action.equals("search")) { if (action.equals("search")) {
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1)); JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
return new PluginResult(status, res); return new PluginResult(status, res);
} }
else if (action.equals("save")) { else if (action.equals("save")) {
String id = contactAccessor.save(args.getJSONObject(0)); String id = contactAccessor.save(args.getJSONObject(0));
if (id != null) { if (id != null) {
JSONObject res = contactAccessor.getContactById(id); JSONObject res = contactAccessor.getContactById(id);
if (res != null) { if (res != null) {
return new PluginResult(status, res); 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);
} }
}
} }