diff options
author | Yorke Lee <yorkelee@google.com> | 2013-08-05 20:34:40 -0700 |
---|---|---|
committer | Yorke Lee <yorkelee@google.com> | 2013-08-22 08:56:13 -0700 |
commit | c36684277aa45085999284bfe71cb8be71b3a464 (patch) | |
tree | f5aab137e7bf3390dfb8e9007b9e289a550ee90d /src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java | |
parent | 2c0ea3b35b9983619c12ab0a4f50e14cc70f801e (diff) |
Rewrite animation logic
* Remove old animation-related code. In the past, animations would be applied to a
view everytime getView was called. This is no longer the case so it fixes the issue of
animations triggering everytime the list was scrolled, dialpad opened, etc.
* Make PhoneFavoriteMergedAdapter (and PhoneFavoritesTileAdapter) return stable IDs, so
that they can be used for animations. The ID schemes are described below:
(N + 1) to -2: CallLogAdapterItems, where N is equal to the number of call log items
-1: All contacts button
0 to (N -1): Rows of tiled contacts, where N is equal to the max rows of tiled contacts
N to infinity: Rows of regular contacts. Their item id is calculated by N + contact_id,
where contact_id is guaranteed to never be negative.
* Perform animations by saving each view's offset before the data set changes, and then
applying a translation animation to them based on their new offsets in the updated list view.
This is the same method described by the framework team at :
http://graphics-geek.blogspot.com/2013/06/devbytes-animating-listview-deletion.html
In our case, we need to perform both horizontal and vertical animations because of the
contact tile favorites.
Bug: 10294203
Change-Id: I3ea4ff9995c539267410a264dbbea5ffa02bc6e3
Diffstat (limited to 'src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java')
-rw-r--r-- | src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java index ce2b6276e..cbb94b22a 100644 --- a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java +++ b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java @@ -42,6 +42,7 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { private static final String TAG = PhoneFavoriteMergedAdapter.class.getSimpleName(); + private static final int ALL_CONTACTS_BUTTON_ITEM_ID = -1; private final PhoneFavoritesTileAdapter mContactTileAdapter; private final CallLogAdapter mCallLogAdapter; private final View mLoadingView; @@ -95,9 +96,35 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { return mContactTileAdapter.getItem(position); } + /** + * In order to ensure that items have stable ids (for animation purposes), we need to + * guarantee that every single item has a unique ID, even across data set changes. + * + * These are the ranges of IDs reserved for each item type. + * + * -(N + 1) to -2: CallLogAdapterItems, where N is equal to the number of call log items + * -1: All contacts button + * 0 to (N -1): Rows of tiled contacts, where N is equal to the max rows of tiled contacts + * N to infinity: Rows of regular contacts. Their item id is calculated by N + contact_id, + * where contact_id is guaranteed to never be negative. + */ @Override public long getItemId(int position) { - return position; + final int callLogAdapterCount = mCallLogAdapter.getCount(); + if (position < callLogAdapterCount) { + // Call log items are not animated, so reusing their position for IDs is fine. + return ALL_CONTACTS_BUTTON_ITEM_ID - 1 - position; + } else if (position < (callLogAdapterCount + mContactTileAdapter.getCount())) { + return mContactTileAdapter.getItemId(position - callLogAdapterCount); + } else { + // All contacts button + return ALL_CONTACTS_BUTTON_ITEM_ID; + } + } + + @Override + public boolean hasStableIds() { + return true; } @Override |