mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-20 23:56:20 +08:00
Cleaning up logs from ContactAccessors
This commit is contained in:
parent
328bc106e5
commit
1768b507f8
@ -24,8 +24,6 @@ import org.json.JSONObject;
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.net.Uri;
|
||||
import android.provider.Contacts.ContactMethods;
|
||||
import android.provider.Contacts.ContactMethodsColumns;
|
||||
import android.provider.Contacts.Organizations;
|
||||
@ -50,10 +48,6 @@ import android.webkit.WebView;
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ContactAccessorSdk3_4 extends ContactAccessor {
|
||||
|
||||
private Uri mPeople = android.provider.Contacts.People.CONTENT_URI;
|
||||
private Uri mPhone = android.provider.Contacts.Phones.CONTENT_URI;
|
||||
private Uri mEmail = android.provider.Contacts.ContactMethods.CONTENT_URI;
|
||||
|
||||
public ContactAccessorSdk3_4(WebView view, Activity app)
|
||||
{
|
||||
mApp = app;
|
||||
@ -62,7 +56,6 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
||||
|
||||
@Override
|
||||
public void search(JSONArray filter, JSONObject options) {
|
||||
Log.d(LOG_TAG, "in 1.5+ search");
|
||||
String searchTerm = "";
|
||||
int limit = Integer.MAX_VALUE;
|
||||
boolean multiple = true;
|
||||
@ -99,7 +92,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
||||
contact.put("phoneNumbers", phoneQuery(cr, contactId));
|
||||
}
|
||||
// email
|
||||
//contact.put("emails", emailQuery(cr, contactId));
|
||||
contact.put("emails", emailQuery(cr, contactId));
|
||||
// addresses
|
||||
contact.put("addresses", addressQuery(cr, contactId));
|
||||
// organizations
|
||||
@ -121,7 +114,6 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
||||
contacts.put(contact);
|
||||
}
|
||||
cur.close();
|
||||
Log.d(LOG_TAG, "returning contacts string to javascript");
|
||||
mView.loadUrl("javascript:navigator.service.contacts.droidDone('" + contacts.toString() + "');");
|
||||
}
|
||||
|
||||
@ -228,7 +220,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
||||
email = new JSONObject();
|
||||
try{
|
||||
email.put("value", cursor.getString(cursor.getColumnIndex(ContactMethods.DATA)));
|
||||
email.put("type", cursor.getString(cursor.getColumnIndex(ContactMethods.TYPE)));
|
||||
//email.put("type", cursor.getString(cursor.getColumnIndex(ContactMethods.TYPE)));
|
||||
emails.put(email);
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOG_TAG, e.getMessage(), e);
|
||||
@ -236,228 +228,4 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
||||
}
|
||||
return emails;
|
||||
}
|
||||
|
||||
private void searchByEmail(String email)
|
||||
{
|
||||
String[] projection = new String[] {
|
||||
ContactMethods._ID,
|
||||
ContactMethods.DATA,
|
||||
ContactMethods.KIND,
|
||||
ContactMethods.PERSON_ID
|
||||
};
|
||||
String[] variables = new String[] {
|
||||
email
|
||||
};
|
||||
|
||||
try{
|
||||
Cursor myCursor = mApp.managedQuery(mEmail, projection,
|
||||
"contact_methods." + ContactMethods.DATA + " = ?" + "AND contact_methods.kind = 1", variables , ContactMethods.DATA + " ASC");
|
||||
getMethodData(myCursor);
|
||||
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
Log.d(this.LOG_TAG, ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void searchPeople(String name, String number)
|
||||
{
|
||||
String conditions = "";
|
||||
|
||||
if (name.length() == 0)
|
||||
{
|
||||
name = "%";
|
||||
conditions += People.NAME + " LIKE ? AND ";
|
||||
}
|
||||
else
|
||||
{
|
||||
conditions += People.NAME + " = ? AND ";
|
||||
}
|
||||
|
||||
if (number.length() == 0)
|
||||
number = "%";
|
||||
else
|
||||
{
|
||||
number = number.replace('+', '%');
|
||||
number = number.replace('.', '%');
|
||||
number = number.replace('-', '%');
|
||||
}
|
||||
|
||||
conditions += People.NUMBER + " LIKE ? ";
|
||||
|
||||
String[] projection = new String[] {
|
||||
People._ID,
|
||||
People.NAME,
|
||||
People.NUMBER,
|
||||
People.PRIMARY_EMAIL_ID
|
||||
};
|
||||
|
||||
String[] variables = new String[] {
|
||||
name, number
|
||||
};
|
||||
|
||||
try{
|
||||
Cursor myCursor = mApp.managedQuery(mPeople, projection,
|
||||
conditions, variables , People.NAME + " ASC");
|
||||
processResults(myCursor, false);
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
Log.d(this.LOG_TAG, ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processResults(Cursor cur, boolean all){
|
||||
|
||||
if (cur.moveToFirst()) {
|
||||
|
||||
String name;
|
||||
String phoneNumber;
|
||||
String email_id;
|
||||
String email;
|
||||
|
||||
int nameColumn = cur.getColumnIndex(People.NAME);
|
||||
int phoneColumn = cur.getColumnIndex(People.NUMBER);
|
||||
int emailIdColumn = cur.getColumnIndex(People.PRIMARY_EMAIL_ID);
|
||||
|
||||
do {
|
||||
// Get the field values
|
||||
name = cur.getString(nameColumn);
|
||||
phoneNumber = cur.getString(phoneColumn);
|
||||
email_id = cur.getString(emailIdColumn);
|
||||
if (email_id != null && email_id.length() > 0)
|
||||
email = getEmail(email_id);
|
||||
else
|
||||
email = "";
|
||||
|
||||
// Code for backwards compatibility with the OLD Contacts API
|
||||
if (all)
|
||||
mView.loadUrl("javascript:navigator.service.ContactManager.droidAddContact('" + name + "','" + phoneNumber + "','" + email +"')");
|
||||
else
|
||||
mView.loadUrl("javascript:navigator.service.contacts.droidFoundContact('" + name + "','" + phoneNumber + "','" + email +"')");
|
||||
|
||||
} while (cur.moveToNext());
|
||||
if (all)
|
||||
mView.loadUrl("javascript:navigator.service.ContactManager.droidDone()");
|
||||
else
|
||||
mView.loadUrl("javascript:navigator.service.contacts.droidDone();");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(all)
|
||||
mView.loadUrl("javascript:navigator.service.ContactManager.fail()");
|
||||
else
|
||||
mView.loadUrl("javascript:navigator.service.contacts.fail('None found!')");
|
||||
}
|
||||
}
|
||||
|
||||
private void getMethodData(Cursor cur)
|
||||
{
|
||||
ContactTriplet data = new ContactTriplet();
|
||||
String id;
|
||||
String email;
|
||||
|
||||
if (cur.moveToFirst()) {
|
||||
|
||||
int idColumn = cur.getColumnIndex(ContactMethods._ID);
|
||||
int emailColumn = cur.getColumnIndex(ContactMethods.DATA);
|
||||
do {
|
||||
// Get the field values
|
||||
id = cur.getString(idColumn);
|
||||
email = cur.getString(emailColumn);
|
||||
|
||||
data = getContactData(id);
|
||||
if(data != null)
|
||||
{
|
||||
data.email = email;
|
||||
mView.loadUrl("javascript:navigator.service.Contacts.droidFoundContact('" + data.name + "','" + data.phone + "','" + data.email +"')");
|
||||
}
|
||||
} while (cur.moveToNext());
|
||||
mView.loadUrl("javascript:navigator.service.contacts.droidDoneContacts();");
|
||||
}
|
||||
}
|
||||
|
||||
private ContactTriplet getContactData(String id) {
|
||||
ContactTriplet data = null;
|
||||
String[] projection = new String[] {
|
||||
People._ID,
|
||||
People.NAME,
|
||||
People.NUMBER,
|
||||
People.PRIMARY_EMAIL_ID
|
||||
};
|
||||
|
||||
String[] variables = new String[] {
|
||||
id
|
||||
};
|
||||
|
||||
try{
|
||||
Cursor myCursor = mApp.managedQuery(mPeople, projection,
|
||||
People.PRIMARY_EMAIL_ID + " = ?", variables , People.NAME + " ASC");
|
||||
data = getTriplet(myCursor);
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
Log.d(LOG_TAG, ex.getMessage());
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private ContactTriplet getTriplet(Cursor cur) {
|
||||
ContactTriplet data = new ContactTriplet();
|
||||
if (cur.moveToFirst()) {
|
||||
|
||||
int nameColumn = cur.getColumnIndex(People.NAME);
|
||||
int numberColumn = cur.getColumnIndex(People.NUMBER);
|
||||
do {
|
||||
|
||||
data.name = cur.getString(nameColumn);
|
||||
data.phone = cur.getString(numberColumn);
|
||||
|
||||
} while (cur.moveToNext());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private String getEmailColumnData(Cursor cur)
|
||||
{
|
||||
String email = "";
|
||||
if (cur != null && cur.moveToFirst()) {
|
||||
int emailColumn = cur.getColumnIndex(ContactMethods.DATA);
|
||||
do {
|
||||
// Get the field values
|
||||
email = cur.getString(emailColumn);
|
||||
} while (cur.moveToNext());
|
||||
}
|
||||
return email;
|
||||
}
|
||||
|
||||
private String getEmail(String id)
|
||||
{
|
||||
String email = "";
|
||||
String[] projection = new String[] {
|
||||
ContactMethods._ID,
|
||||
ContactMethods.DATA,
|
||||
ContactMethods.KIND
|
||||
};
|
||||
String[] variables = new String[] {
|
||||
id
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
Cursor myCursor = mApp.managedQuery(mEmail, projection,
|
||||
"contact_methods." + ContactMethods._ID + " = ?" + " AND contact_methods.kind = 1", variables , ContactMethods.DATA + " ASC");
|
||||
email = getEmailColumnData(myCursor);
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
Log.d(LOG_TAG, ex.getMessage());
|
||||
}
|
||||
|
||||
return email;
|
||||
}
|
||||
}
|
@ -127,7 +127,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
JSONArray organizations = new JSONArray();
|
||||
JSONObject organization = new JSONObject();
|
||||
while (cursor.moveToNext()) {
|
||||
Log.d(LOG_TAG, "We found a organization!");
|
||||
try {
|
||||
organization.put("department", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization.DEPARTMENT)));
|
||||
organization.put("description", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization.JOB_DESCRIPTION)));
|
||||
@ -156,7 +155,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
JSONArray addresses = new JSONArray();
|
||||
JSONObject address = new JSONObject();
|
||||
while (cursor.moveToNext()) {
|
||||
Log.d(LOG_TAG, "We found a address!");
|
||||
try {
|
||||
address.put("formatted", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS)));
|
||||
address.put("streetAddress", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.STREET)));
|
||||
@ -181,7 +179,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
null, addrWhere, addrWhereParams, null);
|
||||
JSONObject contactName = new JSONObject();
|
||||
if (name.moveToFirst()) {
|
||||
Log.d(LOG_TAG, "We found a name!");
|
||||
try {
|
||||
String familyName = name.getString(name.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
|
||||
String givenName = name.getString(name.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
|
||||
@ -220,7 +217,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
JSONArray phoneNumbers = new JSONArray();
|
||||
JSONObject phoneNumber = new JSONObject();
|
||||
while (phones.moveToNext()) {
|
||||
Log.d(LOG_TAG, "We found a phone!");
|
||||
try {
|
||||
phoneNumber.put("primary", false); // Android does not store primary attribute
|
||||
phoneNumber.put("value", phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
|
||||
@ -243,7 +239,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
JSONArray emailAddresses = new JSONArray();
|
||||
JSONObject email = new JSONObject();
|
||||
while (emails.moveToNext()) {
|
||||
Log.d(LOG_TAG, "We found an email!");
|
||||
try {
|
||||
email.put("primary", false);
|
||||
email.put("value", emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)));
|
||||
@ -266,7 +261,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
JSONArray ims = new JSONArray();
|
||||
JSONObject im = new JSONObject();
|
||||
while (cursor.moveToNext()) {
|
||||
Log.d(LOG_TAG, "We found IM's!");
|
||||
try {
|
||||
im.put("primary", false);
|
||||
im.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
|
||||
@ -288,7 +282,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
null, noteWhere, noteWhereParams, null);
|
||||
String note = new String("");
|
||||
if (cursor.moveToFirst()) {
|
||||
Log.d(LOG_TAG, "We found a note!");
|
||||
note = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));
|
||||
}
|
||||
cursor.close();
|
||||
@ -303,7 +296,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
null, nicknameWhere, nicknameWhereParams, null);
|
||||
String nickname = new String("");
|
||||
if (cursor.moveToFirst()) {
|
||||
Log.d(LOG_TAG, "We found a nickname!");
|
||||
nickname = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME));
|
||||
}
|
||||
cursor.close();
|
||||
@ -319,7 +311,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
JSONArray websites = new JSONArray();
|
||||
JSONObject website = new JSONObject();
|
||||
while (cursor.moveToNext()) {
|
||||
Log.d(LOG_TAG, "We found websites!");
|
||||
try {
|
||||
website.put("primary", false);
|
||||
website.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Website.URL)));
|
||||
@ -342,7 +333,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
JSONArray relationships = new JSONArray();
|
||||
JSONObject relationship = new JSONObject();
|
||||
while (cursor.moveToNext()) {
|
||||
Log.d(LOG_TAG, "We found a relationship!");
|
||||
try {
|
||||
relationship.put("primary", false);
|
||||
relationship.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Relation.NAME)));
|
||||
@ -360,7 +350,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
String birthday = conditionalStringQuery(cr, contactId, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE,
|
||||
ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY, ContactsContract.CommonDataKinds.Event.TYPE,
|
||||
ContactsContract.CommonDataKinds.Event.START_DATE);
|
||||
Log.d(LOG_TAG, birthday);
|
||||
return birthday;
|
||||
}
|
||||
|
||||
@ -368,7 +357,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
String anniversary = conditionalStringQuery(cr, contactId, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE,
|
||||
ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY, ContactsContract.CommonDataKinds.Event.TYPE,
|
||||
ContactsContract.CommonDataKinds.Event.START_DATE);
|
||||
Log.d(LOG_TAG, anniversary);
|
||||
return anniversary;
|
||||
}
|
||||
|
||||
@ -379,7 +367,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
null, where, whereParams, null);
|
||||
String retVal = new String("");
|
||||
while (cursor.moveToNext()) {
|
||||
Log.d(LOG_TAG, "We found an event!");
|
||||
if (type == cursor.getInt(cursor.getColumnIndex(label))) {
|
||||
retVal = cursor.getString(cursor.getColumnIndex(data));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user