summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJin Cao <jinyan@google.com>2014-08-07 09:49:35 -0700
committerJin Cao <jinyan@google.com>2014-08-07 10:21:53 -0700
commit0e424db6bc5cfbb7f8d980fb9d184f0835bb1fe3 (patch)
tree087470d7cf3789aab669189c62f3b287afef416d /src
parent9d4b37f0572a8f876b1cc6d873f9ccf0805dd0e4 (diff)
downloadandroid_packages_apps_UnifiedEmail-0e424db6bc5cfbb7f8d980fb9d184f0835bb1fe3.tar.gz
android_packages_apps_UnifiedEmail-0e424db6bc5cfbb7f8d980fb9d184f0835bb1fe3.tar.bz2
android_packages_apps_UnifiedEmail-0e424db6bc5cfbb7f8d980fb9d184f0835bb1fe3.zip
Fix position offset for special views
The position for special views should take header views into account since the special views start at index 0. The NPE was caused when we are supposed to return a special view. However, since the index is off, the special view is null and the offset position is -1. b/16728934 Change-Id: I83bc5059a52b2d824c929acbafc6895094999d28
Diffstat (limited to 'src')
-rw-r--r--src/com/android/mail/ui/AnimatedAdapter.java24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/com/android/mail/ui/AnimatedAdapter.java b/src/com/android/mail/ui/AnimatedAdapter.java
index 5eeee2a4d..843665847 100644
--- a/src/com/android/mail/ui/AnimatedAdapter.java
+++ b/src/com/android/mail/ui/AnimatedAdapter.java
@@ -400,7 +400,7 @@ public class AnimatedAdapter extends SimpleCursorAdapter {
// types. In a future release, use position/id map to try to make
// this cleaner / faster to determine if the view is animating.
return TYPE_VIEW_DONT_RECYCLE;
- } else if (mSpecialViews.get(position) != null) {
+ } else if (mSpecialViews.get(getSpecialViewsPos(position)) != null) {
// Don't recycle the special views
return TYPE_VIEW_DONT_RECYCLE;
}
@@ -477,7 +477,8 @@ public class AnimatedAdapter extends SimpleCursorAdapter {
}
// Check if this is a special view
- final ConversationSpecialItemView specialView = mSpecialViews.get(position);
+ final ConversationSpecialItemView specialView = mSpecialViews.get(
+ getSpecialViewsPos(position));
if (specialView != null) {
specialView.onGetView();
return (View) specialView;
@@ -702,7 +703,8 @@ public class AnimatedAdapter extends SimpleCursorAdapter {
return -1;
}
- final ConversationSpecialItemView specialView = mSpecialViews.get(position);
+ final ConversationSpecialItemView specialView = mSpecialViews.get(
+ getSpecialViewsPos(position));
if (specialView != null) {
// TODO(skennedy) We probably want something better than this
return specialView.hashCode();
@@ -784,12 +786,14 @@ public class AnimatedAdapter extends SimpleCursorAdapter {
@Override
public Object getItem(int position) {
+ final ConversationSpecialItemView specialView = mSpecialViews.get(
+ getSpecialViewsPos(position));
if (mHeaders.size() > position) {
return mHeaders.get(position);
} else if (mShowFooter && position == getCount() - 1) {
return mFooter;
- } else if (mSpecialViews.get(position) != null) {
- return mSpecialViews.get(position);
+ } else if (specialView != null) {
+ return specialView;
}
return super.getItem(position - getPositionOffset(position));
}
@@ -1106,9 +1110,10 @@ public class AnimatedAdapter extends SimpleCursorAdapter {
* Gets the offset for the given position in the underlying cursor, based on any special views
* that may be above it.
*/
- public int getPositionOffset(final int position) {
+ public int getPositionOffset(int position) {
int viewsAbove = mHeaders.size();
+ position -= viewsAbove;
for (int i = 0, size = mSpecialViews.size(); i < size; i++) {
final int bidPosition = mSpecialViews.keyAt(i);
// If the view bid for a position above the cursor position,
@@ -1121,6 +1126,13 @@ public class AnimatedAdapter extends SimpleCursorAdapter {
return viewsAbove;
}
+ /**
+ * Gets the correct position for special views given the number of headers we have.
+ */
+ private int getSpecialViewsPos(final int position) {
+ return position - mHeaders.size();
+ }
+
public void cleanup() {
// Clean up teaser views.
for (final ConversationSpecialItemView view : mFleetingViews) {