incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject android commit: spacing fixes, null check in getPhoneType in contacts, returning error integers instead of objects in contacts
Date Thu, 15 Mar 2012 19:27:51 GMT
Updated Branches:
  refs/heads/master df691518e -> 692a59a69


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


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/692a59a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/692a59a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/692a59a6

Branch: refs/heads/master
Commit: 692a59a69255f10d5cb6c007a1684f17a0d9e0a4
Parents: df69151
Author: Fil Maj <maj.fil@gmail.com>
Authored: Thu Mar 15 12:03:20 2012 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Thu Mar 15 12:27:37 2012 -0700

----------------------------------------------------------------------
 .../org/apache/cordova/ContactAccessorSdk5.java    |  132 ++++++++-------
 .../src/org/apache/cordova/ContactManager.java     |  114 ++++++-------
 2 files changed, 118 insertions(+), 128 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/692a59a6/framework/src/org/apache/cordova/ContactAccessorSdk5.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/ContactAccessorSdk5.java b/framework/src/org/apache/cordova/ContactAccessorSdk5.java
index 6776819..6adcf00 100644
--- a/framework/src/org/apache/cordova/ContactAccessorSdk5.java
+++ b/framework/src/org/apache/cordova/ContactAccessorSdk5.java
@@ -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;
   }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/692a59a6/framework/src/org/apache/cordova/ContactManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/ContactManager.java b/framework/src/org/apache/cordova/ContactManager.java
index 2b12413..ebe9ede 100755
--- a/framework/src/org/apache/cordova/ContactManager.java
+++ b/framework/src/org/apache/cordova/ContactManager.java
@@ -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() {
+    }
 
-  
-  /**
-   * 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 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);
-                  }
-        }
-      }
-      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);
     }
-  }
 }


Mime
View raw message