summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2014-02-10 16:09:12 -0800
committerYorke Lee <yorkelee@google.com>2014-02-18 15:24:31 -0800
commit765734c1d602c9a6d166d653b3684e6408b771c4 (patch)
tree63536c7e4eda26db6e14d29b3ce21099d50ce8de /tests
parentf5a48b2f7ea7d69162f48ea47a6bf30ba098b5c4 (diff)
downloadandroid_packages_apps_Dialer-765734c1d602c9a6d166d653b3684e6408b771c4.tar.gz
android_packages_apps_Dialer-765734c1d602c9a6d166d653b3684e6408b771c4.tar.bz2
android_packages_apps_Dialer-765734c1d602c9a6d166d653b3684e6408b771c4.zip
Switch favorites screen to grid layout
* Add logic to PhoneFavoritesTileAdapter so that it now supports an unlimited number of tiled rows. * Tiles now have a configurable height to width ratio. * Fix animations so that tiles moving up and down rows appear to animate in from the correct direction. Tiles moving to the row above should animate in from right to left. Tiles moving to the row below should animate in from left to right. * Update the number of columns in the grid to 2. * Update layout of individual tiles to match redlines from UX. * Tweak font sizes for tiles * No longer truncate names in tiles * Tiles have a 2-3 height to width ratio * Update assets and layout for favorite and more info icons * Add content description for the favorite button * Add tests for PhoneFavoritesTileAdapter Change-Id: I50b298f0941698985d281f13e6a87c5a9b613efa
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java140
1 files changed, 135 insertions, 5 deletions
diff --git a/tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java b/tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java
index 611b3f1af..7a2076d8e 100644
--- a/tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java
+++ b/tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java
@@ -1,15 +1,26 @@
package com.android.dialer.list;
+import android.database.Cursor;
+import android.database.MatrixCursor;
+import android.provider.ContactsContract.PinnedPositions;
import android.test.AndroidTestCase;
+import com.android.contacts.common.ContactTileLoaderFactory;
+import com.android.contacts.common.list.ContactEntry;
+import com.android.dialer.list.PhoneFavoritesTileAdapter.OnDataSetChangedForAnimationListener;
+
+import java.util.ArrayList;
+
public class PhoneFavoritesTileAdapterTest extends AndroidTestCase {
private PhoneFavoritesTileAdapter mAdapter;
+ private static final OnDataSetChangedForAnimationListener
+ sOnDataSetChangedForAnimationListener = new OnDataSetChangedForAnimationListener() {
+ @Override
+ public void onDataSetChangedForAnimation(long... idsInPlace) {}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mAdapter = new PhoneFavoritesTileAdapter(getContext(), null, null, 3, 1);
- }
+ @Override
+ public void cacheOffsetsForDatasetChange() {}
+ };
/**
* TODO: Add tests
@@ -42,5 +53,124 @@ public class PhoneFavoritesTileAdapterTest extends AndroidTestCase {
}
+ public void testGetRowIndex_NoRowLimit() {
+ mAdapter = getAdapterForTest(2, PhoneFavoritesTileAdapter.NO_ROW_LIMIT);
+ assertEquals(0, mAdapter.getRowCount(0));
+ assertEquals(1, mAdapter.getRowCount(1));
+ assertEquals(1, mAdapter.getRowCount(2));
+ assertEquals(2, mAdapter.getRowCount(4));
+ assertEquals(4, mAdapter.getRowCount(7));
+ assertEquals(100, mAdapter.getRowCount(199));
+
+ mAdapter = getAdapterForTest(5, PhoneFavoritesTileAdapter.NO_ROW_LIMIT);
+ assertEquals(0, mAdapter.getRowCount(0));
+ assertEquals(1, mAdapter.getRowCount(1));
+ assertEquals(1, mAdapter.getRowCount(3));
+ assertEquals(1, mAdapter.getRowCount(5));
+ assertEquals(2, mAdapter.getRowCount(7));
+ assertEquals(2, mAdapter.getRowCount(10));
+ assertEquals(40, mAdapter.getRowCount(199));
+ }
+
+ public void testGetItemId_NoRowLimit() {
+ mAdapter = getAdapterForTest(2, PhoneFavoritesTileAdapter.NO_ROW_LIMIT);
+ assertEquals(0, mAdapter.getItemId(0));
+ assertEquals(1, mAdapter.getItemId(1));
+ assertEquals(5, mAdapter.getItemId(5));
+ assertEquals(10, mAdapter.getItemId(10));
+ }
+
+ public void testGetAdjustedItemId_NoRowLimit() {
+ mAdapter = getAdapterForTest(2, PhoneFavoritesTileAdapter.NO_ROW_LIMIT);
+ assertEquals(0, mAdapter.getAdjustedItemId(0));
+ assertEquals(1, mAdapter.getAdjustedItemId(1));
+ assertEquals(5, mAdapter.getAdjustedItemId(5));
+ assertEquals(10, mAdapter.getAdjustedItemId(10));
+ }
+ public void testGetItem_NoRowLimit() {
+ mAdapter = getAdapterForTest(2, PhoneFavoritesTileAdapter.NO_ROW_LIMIT);
+ mAdapter.setContactCursor(getCursorForTest(5, 5));
+
+ final ArrayList<ContactEntry> row1 = new ArrayList<ContactEntry> ();
+ row1.add(getTestContactEntry(0, true));
+ row1.add(getTestContactEntry(1, true));
+ assertContactEntryRowsEqual(row1, mAdapter.getItem(0));
+
+ final ArrayList<ContactEntry> row3 = new ArrayList<ContactEntry> ();
+ row3.add(getTestContactEntry(4, true));
+ row3.add(getTestContactEntry(5, false));
+ assertContactEntryRowsEqual(row3, mAdapter.getItem(2));
+
+ final ArrayList<ContactEntry> row5 = new ArrayList<ContactEntry> ();
+ row5.add(getTestContactEntry(8, false));
+ row5.add(getTestContactEntry(9, false));
+ assertContactEntryRowsEqual(row5, mAdapter.getItem(4));
+ }
+
+ /**
+ * Ensures that PhoneFavoritesTileAdapter returns true for hasStableIds. This is needed for
+ * animation purposes.
+ */
+ public void testHasStableIds() {
+ mAdapter = new PhoneFavoritesTileAdapter(getContext(), null, null, 2, 2);
+ assertTrue(mAdapter.hasStableIds());
+ }
+
+ private PhoneFavoritesTileAdapter getAdapterForTest(int numCols, int numRows) {
+ return new PhoneFavoritesTileAdapter(getContext(), null,
+ sOnDataSetChangedForAnimationListener, numCols, numRows);
+ }
+
+ /**
+ * Returns a cursor containing starred and frequent contacts for test purposes.
+ *
+ * @param numStarred Number of starred contacts in the cursor. Cannot be a negative number.
+ * @param numFrequents Number of frequent contacts in the cursor. Cannot be a negative number.
+ * @return Cursor containing the required number of rows, each representing one ContactEntry
+ */
+ private Cursor getCursorForTest(int numStarred, int numFrequents) {
+ assertTrue(numStarred >= 0);
+ assertTrue(numFrequents >= 0);
+ final MatrixCursor c = new MatrixCursor(ContactTileLoaderFactory.COLUMNS_PHONE_ONLY);
+ int countId = 0;
+
+ // Add starred contact entries. These entries have the starred field set to 1 (true).
+ // The only field that really matters for testing is the contact id.
+ for (int i = 0; i < numStarred; i++) {
+ c.addRow(new Object[] {countId, null, 1, null, null, 0, 0, null, 0,
+ PinnedPositions.UNPINNED, countId});
+ countId++;
+ }
+
+ // Add frequent contact entries. These entries have the starred field set to 0 (false).
+ for (int i = 0; i < numFrequents; i++) {
+ c.addRow(new Object[] {countId, null, 0, null, null, 0, 0, null, 0,
+ PinnedPositions.UNPINNED, countId});
+ countId++;
+ }
+ return c;
+ }
+
+ /**
+ * Returns a ContactEntry with test data corresponding to the provided contact Id
+ *
+ * @param id Non-negative id
+ * @return ContactEntry item used for testing
+ */
+ private ContactEntry getTestContactEntry(int id, boolean isFavorite) {
+ ContactEntry contactEntry = new ContactEntry();
+ contactEntry.id = id;
+ contactEntry.isFavorite = isFavorite;
+ return contactEntry;
+ }
+
+ private void assertContactEntryRowsEqual(ArrayList<ContactEntry> expected,
+ ArrayList<ContactEntry> actual) {
+ assertEquals(expected.size(), actual.size());
+ for (int i = 0; i < actual.size(); i++) {
+ assertEquals(expected.get(i).id, actual.get(i).id);
+ assertEquals(expected.get(i).isFavorite, actual.get(i).isFavorite);
+ }
+ }
}