summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2013-04-06 00:07:21 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-04-06 00:07:21 +0000
commitbccd23a1790f0fef1a85fa2a78799517c9024de5 (patch)
tree1a4961285ecce3e151d8fd1138e8e9bbd638972f
parent0d5e72ebd7945bbe106f267db2120df9bb776957 (diff)
parent9eedc6d0bcf96bb888e2839fa0fa5e7959553caa (diff)
Merge "Sort by data usage for smart dialing" into jb-mr2-dev
-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");
}