summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2013-04-03 11:41:20 -0700
committerYorke Lee <yorkelee@google.com>2013-04-05 16:54:37 -0700
commit9eedc6d0bcf96bb888e2839fa0fa5e7959553caa (patch)
treed30530a3cdbebf51a06d68e613d576591b9d5703
parentf43f537a0100693570606c436a81a12e21fb5b9e (diff)
Sort by data usage for smart dialing
Bug 8281648 Change-Id: I55bfaf137f9657a47616187fe7b7999c321b21f9
-rw-r--r--src/com/android/dialer/dialpad/SmartDialCache.java33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/com/android/dialer/dialpad/SmartDialCache.java b/src/com/android/dialer/dialpad/SmartDialCache.java
index 4f4ce1469..79cc72763 100644
--- a/src/com/android/dialer/dialpad/SmartDialCache.java
+++ b/src/com/android/dialer/dialpad/SmartDialCache.java
@@ -26,6 +26,7 @@ import android.os.Handler;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
+import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.Directory;
import android.util.Log;
@@ -104,7 +105,33 @@ public class SmartDialCache {
public static final int PHONE_LOOKUP_KEY = 5;
public static final int PHONE_DISPLAY_NAME = 6;
- public static final String SORT_ORDER = Contacts.LAST_TIME_CONTACTED + " DESC";
+ // Current contacts - those contacted within the last 3 days (in milliseconds)
+ final static long LAST_TIME_USED_CURRENT_MS = 3 * 24 * 60 * 60 * 1000;
+
+ // Recent contacts - those contacted within the last 30 days (in milliseconds)
+ final static long LAST_TIME_USED_RECENT_MS = 30 * 24 * 60 * 60 * 1000;
+
+ final static String TIME_SINCE_LAST_USED_MS =
+ "(? - " + Data.LAST_TIME_USED + ")";
+
+ final static String SORT_BY_DATA_USAGE =
+ "(CASE WHEN " + TIME_SINCE_LAST_USED_MS + " < " + LAST_TIME_USED_CURRENT_MS +
+ " THEN 0 " +
+ " WHEN " + TIME_SINCE_LAST_USED_MS + " < " + LAST_TIME_USED_RECENT_MS +
+ " THEN 1 " +
+ " ELSE 2 END), " +
+ Data.TIMES_USED + " DESC";
+
+ // This sort order is similar to that used by the ContactsProvider when returning a list
+ // of frequently called contacts.
+ public static final String SORT_ORDER =
+ Contacts.STARRED + " DESC, "
+ + Data.IS_SUPER_PRIMARY + " DESC, "
+ + SORT_BY_DATA_USAGE + ", "
+ + Contacts.IN_VISIBLE_GROUP + " DESC, "
+ + Contacts.DISPLAY_NAME + ", "
+ + Data.CONTACT_ID + ", "
+ + Data.IS_PRIMARY + " DESC";
}
private SmartDialTrie mContactsCache;
@@ -155,10 +182,12 @@ public class SmartDialCache {
Log.d(LOG_TAG, "Starting caching thread");
}
final StopWatch stopWatch = DEBUG ? StopWatch.start("SmartDial Cache") : null;
+ final String millis = String.valueOf(System.currentTimeMillis());
final Cursor c = context.getContentResolver().query(PhoneQuery.URI,
(mNameDisplayOrder == ContactsContract.Preferences.DISPLAY_ORDER_PRIMARY)
? PhoneQuery.PROJECTION_PRIMARY : PhoneQuery.PROJECTION_ALTERNATIVE,
- null, null, PhoneQuery.SORT_ORDER);
+ null, new String[] {millis, millis},
+ PhoneQuery.SORT_ORDER);
if (DEBUG) {
stopWatch.lap("SmartDial query complete");
}