forked from github/cordova-android
Shave .2 sec off each contact returned in a query
This commit is contained in:
parent
a1b35b7636
commit
f20e5cf943
@ -114,6 +114,10 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONArray search(JSONArray filter, JSONObject options) {
|
public JSONArray search(JSONArray filter, JSONObject options) {
|
||||||
|
long totalEnd;
|
||||||
|
long totalStart = System.currentTimeMillis();
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
long stop;
|
||||||
String searchTerm = "";
|
String searchTerm = "";
|
||||||
int limit = Integer.MAX_VALUE;
|
int limit = Integer.MAX_VALUE;
|
||||||
boolean multiple = true;
|
boolean multiple = true;
|
||||||
@ -132,18 +136,25 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(LOG_TAG, e.getMessage(), e);
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
stop = System.currentTimeMillis();
|
||||||
|
Log.d(LOG_TAG, "Parsing parameters took = " + (stop-start));
|
||||||
|
start = System.currentTimeMillis();
|
||||||
|
|
||||||
// Get a cursor by creating the query.
|
// Get a cursor by creating the query.
|
||||||
ContentResolver cr = mApp.getContentResolver();
|
ContentResolver cr = mApp.getContentResolver();
|
||||||
|
|
||||||
Set<String> contactIds = buildSetOfContactIds(filter, searchTerm);
|
Set<String> contactIds = buildSetOfContactIds(filter, searchTerm);
|
||||||
|
|
||||||
|
stop = System.currentTimeMillis();
|
||||||
|
Log.d(LOG_TAG, "Building contact ID's took = " + (stop-start));
|
||||||
|
|
||||||
Iterator<String> it = contactIds.iterator();
|
Iterator<String> it = contactIds.iterator();
|
||||||
|
|
||||||
JSONArray contacts = new JSONArray();
|
JSONArray contacts = new JSONArray();
|
||||||
JSONObject contact;
|
JSONObject contact;
|
||||||
String contactId;
|
String contactId;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
String[] events = null;
|
||||||
while (it.hasNext() && (pos < limit)) {
|
while (it.hasNext() && (pos < limit)) {
|
||||||
contact = new JSONObject();
|
contact = new JSONObject();
|
||||||
contactId = it.next();
|
contactId = it.next();
|
||||||
@ -161,8 +172,9 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
contact.put("nickname",nicknameQuery(cr, contactId));
|
contact.put("nickname",nicknameQuery(cr, contactId));
|
||||||
contact.put("urls",websiteQuery(cr, contactId));
|
contact.put("urls",websiteQuery(cr, contactId));
|
||||||
contact.put("relationships",relationshipQuery(cr, contactId));
|
contact.put("relationships",relationshipQuery(cr, contactId));
|
||||||
contact.put("birthday",birthdayQuery(cr, contactId));
|
events = eventQuery(cr, contactId);
|
||||||
contact.put("anniversary",anniversaryQuery(cr, contactId));
|
contact.put("birthday",events[0]);
|
||||||
|
contact.put("anniversary",events[1]);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(LOG_TAG, e.getMessage(), e);
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
@ -171,6 +183,10 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
contacts.put(contact);
|
contacts.put(contact);
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
stop = System.currentTimeMillis();
|
||||||
|
totalEnd = System.currentTimeMillis();
|
||||||
|
Log.d(LOG_TAG, "Populating contact Array took = " + (stop - start));
|
||||||
|
Log.d(LOG_TAG, "Total search took = " + (totalEnd - totalStart));
|
||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,32 +571,22 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
return relationships;
|
return relationships;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String birthdayQuery(ContentResolver cr, String contactId) {
|
private String[] eventQuery(ContentResolver cr, String contactId) {
|
||||||
String birthday = conditionalStringQuery(cr, contactId, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE,
|
String[] whereParams = new String[]{contactId, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE};
|
||||||
ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY, ContactsContract.CommonDataKinds.Event.TYPE,
|
|
||||||
ContactsContract.CommonDataKinds.Event.START_DATE);
|
|
||||||
return birthday;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String anniversaryQuery(ContentResolver cr, String contactId) {
|
|
||||||
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);
|
|
||||||
return anniversary;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String conditionalStringQuery(ContentResolver cr, String contactId, String dataType, int type, String label, String data) {
|
|
||||||
String[] whereParams = new String[]{contactId, dataType};
|
|
||||||
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
||||||
null, WHERE_STRING, whereParams, null);
|
null, WHERE_STRING, whereParams, null);
|
||||||
String retVal = new String("");
|
String anniversary = null;
|
||||||
|
String birthday = null;
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
if (type == cursor.getInt(cursor.getColumnIndex(label))) {
|
if (ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY == cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE))) {
|
||||||
retVal = cursor.getString(cursor.getColumnIndex(data));
|
anniversary = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE));
|
||||||
|
}
|
||||||
|
else if (ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY == cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE))) {
|
||||||
|
birthday = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
return retVal;
|
return new String[] {anniversary, birthday};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user