am 913bf804: Merge "Don\'t allow apps to request scrolls to out-of-bounds positions" into jb-dev

* commit '913bf80416a81f2783376939e7ad0b956975b05c':
  Don't allow apps to request scrolls to out-of-bounds positions
This commit is contained in:
Chet Haase
2012-06-10 12:33:19 -07:00
committed by Android Git Automerger

View File

@@ -4305,14 +4305,15 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
final int lastPos = firstPos + childCount - 1; final int lastPos = firstPos + childCount - 1;
int viewTravelCount; int viewTravelCount;
if (position < firstPos) { int clampedPosition = Math.max(0, Math.min(getCount() - 1, position));
viewTravelCount = firstPos - position + 1; if (clampedPosition < firstPos) {
viewTravelCount = firstPos - clampedPosition + 1;
mMode = MOVE_UP_POS; mMode = MOVE_UP_POS;
} else if (position > lastPos) { } else if (clampedPosition > lastPos) {
viewTravelCount = position - lastPos + 1; viewTravelCount = clampedPosition - lastPos + 1;
mMode = MOVE_DOWN_POS; mMode = MOVE_DOWN_POS;
} else { } else {
scrollToVisible(position, INVALID_POSITION, SCROLL_DURATION); scrollToVisible(clampedPosition, INVALID_POSITION, SCROLL_DURATION);
return; return;
} }
@@ -4321,7 +4322,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
} else { } else {
mScrollDuration = SCROLL_DURATION; mScrollDuration = SCROLL_DURATION;
} }
mTargetPos = position; mTargetPos = clampedPosition;
mBoundPos = INVALID_POSITION; mBoundPos = INVALID_POSITION;
mLastSeenPos = INVALID_POSITION; mLastSeenPos = INVALID_POSITION;
@@ -4356,14 +4357,15 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
final int lastPos = firstPos + childCount - 1; final int lastPos = firstPos + childCount - 1;
int viewTravelCount; int viewTravelCount;
if (position < firstPos) { int clampedPosition = Math.max(0, Math.min(getCount() - 1, position));
if (clampedPosition < firstPos) {
final int boundPosFromLast = lastPos - boundPosition; final int boundPosFromLast = lastPos - boundPosition;
if (boundPosFromLast < 1) { if (boundPosFromLast < 1) {
// Moving would shift our bound position off the screen. Abort. // Moving would shift our bound position off the screen. Abort.
return; return;
} }
final int posTravel = firstPos - position + 1; final int posTravel = firstPos - clampedPosition + 1;
final int boundTravel = boundPosFromLast - 1; final int boundTravel = boundPosFromLast - 1;
if (boundTravel < posTravel) { if (boundTravel < posTravel) {
viewTravelCount = boundTravel; viewTravelCount = boundTravel;
@@ -4372,14 +4374,14 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
viewTravelCount = posTravel; viewTravelCount = posTravel;
mMode = MOVE_UP_POS; mMode = MOVE_UP_POS;
} }
} else if (position > lastPos) { } else if (clampedPosition > lastPos) {
final int boundPosFromFirst = boundPosition - firstPos; final int boundPosFromFirst = boundPosition - firstPos;
if (boundPosFromFirst < 1) { if (boundPosFromFirst < 1) {
// Moving would shift our bound position off the screen. Abort. // Moving would shift our bound position off the screen. Abort.
return; return;
} }
final int posTravel = position - lastPos + 1; final int posTravel = clampedPosition - lastPos + 1;
final int boundTravel = boundPosFromFirst - 1; final int boundTravel = boundPosFromFirst - 1;
if (boundTravel < posTravel) { if (boundTravel < posTravel) {
viewTravelCount = boundTravel; viewTravelCount = boundTravel;
@@ -4389,7 +4391,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
mMode = MOVE_DOWN_POS; mMode = MOVE_DOWN_POS;
} }
} else { } else {
scrollToVisible(position, boundPosition, SCROLL_DURATION); scrollToVisible(clampedPosition, boundPosition, SCROLL_DURATION);
return; return;
} }
@@ -4398,7 +4400,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
} else { } else {
mScrollDuration = SCROLL_DURATION; mScrollDuration = SCROLL_DURATION;
} }
mTargetPos = position; mTargetPos = clampedPosition;
mBoundPos = boundPosition; mBoundPos = boundPosition;
mLastSeenPos = INVALID_POSITION; mLastSeenPos = INVALID_POSITION;
@@ -4431,7 +4433,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
offset += getPaddingTop(); offset += getPaddingTop();
mTargetPos = position; mTargetPos = Math.max(0, Math.min(getCount() - 1, position));
mOffsetFromTop = offset; mOffsetFromTop = offset;
mBoundPos = INVALID_POSITION; mBoundPos = INVALID_POSITION;
mLastSeenPos = INVALID_POSITION; mLastSeenPos = INVALID_POSITION;
@@ -4441,13 +4443,13 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
final int lastPos = firstPos + childCount - 1; final int lastPos = firstPos + childCount - 1;
int viewTravelCount; int viewTravelCount;
if (position < firstPos) { if (mTargetPos < firstPos) {
viewTravelCount = firstPos - position; viewTravelCount = firstPos - mTargetPos;
} else if (position > lastPos) { } else if (mTargetPos > lastPos) {
viewTravelCount = position - lastPos; viewTravelCount = mTargetPos - lastPos;
} else { } else {
// On-screen, just scroll. // On-screen, just scroll.
final int targetTop = getChildAt(position - firstPos).getTop(); final int targetTop = getChildAt(mTargetPos - firstPos).getTop();
smoothScrollBy(targetTop - offset, duration, true); smoothScrollBy(targetTop - offset, duration, true);
return; return;
} }