Permalink
Browse files

spacing fixes, null check in getPhoneType in contacts, returning erro…

…r integers instead of objects in contacts
  • Loading branch information...
1 parent df69151 commit 692a59a69255f10d5cb6c007a1684f17a0d9e0a4 @filmaj filmaj committed Mar 15, 2012
@@ -1649,71 +1649,73 @@ public boolean remove(String id) {
*/
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;
}
@@ -26,52 +26,42 @@ Licensed to the Apache Software Foundation (ASF) under one
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() {
+ }
-
- /**
- * 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) {
+ /**
+ * 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 PluginResult execute(String action, JSONArray args, String callbackId) {
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);
- }
- }
- }
- else if (action.equals("remove")) {
- if (contactAccessor.remove(args.getString(0))) {
- return new PluginResult(status, result);
+
+ 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);
}
- }
- // 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);
}
- }
}

0 comments on commit 692a59a

Please sign in to comment.