am 7036039d: am 6bf6d90f: Merge "Restrict the cap # of frequents on home screen to 20" into klp-dev

* commit '7036039db1ec107d2cffbfa1395085c3add59c4b':
  Restrict the cap # of frequents on home screen to 20
diff --git a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
index 263794f..1c6ffde 100644
--- a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
+++ b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
@@ -121,6 +121,15 @@
 
     private static final int PIN_LIMIT = 20;
 
+    /**
+     * The soft limit on how many contact tiles to show.
+     * NOTE This soft limit would not restrict the number of starred contacts to show, rather
+     * 1. If the count of starred contacts is less than this limit, show 20 tiles total.
+     * 2. If the count of starred contacts is more than or equal to this limit,
+     * show all starred tiles and no frequents.
+     */
+    private static final int TILES_SOFT_LIMIT = 20;
+
     final Comparator<ContactEntry> mContactEntryComparator = new Comparator<ContactEntry>() {
         @Override
         public int compare(ContactEntry lhs, ContactEntry rhs) {
@@ -254,6 +263,9 @@
 
         final Object dummy = new Object();
 
+        // Track the length of {@link #mContactEntries} and compare to {@link #TILES_SOFT_LIMIT}.
+        int counter = 0;
+
         while (cursor.moveToNext()) {
 
             final int starred = cursor.getInt(mStarredIndex);
@@ -261,6 +273,8 @@
 
             if (starred > 0) {
                 id = cursor.getLong(mIdIndex);
+            } else if (counter >= TILES_SOFT_LIMIT) {
+                break;
             } else {
                 // The contact id for frequent contacts is stored in the .contact_id field rather
                 // than the _id field
@@ -305,6 +319,8 @@
 
             contact.pinned = pinned;
             mContactEntries.add(contact);
+
+            counter++;
         }
 
         mAwaitingRemove = false;