Adding Contact.remove method

This commit is contained in:
macdonst
2010-10-01 11:09:59 +08:00
parent 668bc9e0ca
commit 6071b9c75a
6 changed files with 86 additions and 18 deletions
@@ -83,8 +83,18 @@ public abstract class ContactAccessor {
return sInstance;
}
/**
* Handles adding a JSON Contact object into the database.
*/
public abstract void save();
/**
* Handles searching through SDK-specific contacts API.
*/
public abstract void search(JSONArray filter, JSONObject options);
/**
* Handles removing a contact from the database.
*/
public abstract boolean remove(String id);
}
@@ -31,6 +31,7 @@ import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.Contacts.ContactMethods;
import android.provider.Contacts.ContactMethodsColumns;
import android.provider.Contacts.Organizations;
@@ -359,4 +360,22 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
}
return emails;
}
@Override
public void save() {
// TODO Auto-generated method stub
}
@Override
public boolean remove(String id) {
ContentResolver cr = mApp.getContentResolver();
int result = cr.delete(People.CONTENT_URI, "people._id = ?", new String[] {id});
Log.d(LOG_TAG, "Content URI = " + People.CONTENT_URI);
Log.d(LOG_TAG, "Where = " + "people._id = ?");
Log.d(LOG_TAG, "Number of rows deleted = " + result);
return (result > 0) ? true : false;
}
}
@@ -549,5 +549,23 @@ public class ContactAccessorSdk5 extends ContactAccessor {
}
cursor.close();
return retVal;
}
@Override
public void save() {
// TODO Auto-generated method stub
}
@Override
public boolean remove(String id) {
ContentResolver cr = mApp.getContentResolver();
int result = cr.delete(ContactsContract.Data.CONTENT_URI,
ContactsContract.Data.CONTACT_ID + " = ?",
new String[] {id});
Log.d(LOG_TAG, "Content URI = " + ContactsContract.Data.CONTENT_URI);
Log.d(LOG_TAG, "Where = " + ContactsContract.Data.CONTACT_ID + " = ?");
Log.d(LOG_TAG, "Number of rows deleted = " + result);
return (result > 0) ? true : false;
}
}
@@ -2,6 +2,7 @@ package com.phonegap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
@@ -69,7 +70,14 @@ public class ContactManager implements Plugin {
// TODO Coming soon!
}
else if (action.equals("remove")) {
// TODO Coming soon!
if (contactAccessor.remove(args.getString(0))) {
return new PluginResult(status, result);
}
else {
JSONObject r = new JSONObject();
r.put("code", 2);
return new PluginResult(PluginResult.Status.ERROR, r);
}
}
return new PluginResult(status, result);
} catch (JSONException e) {