am 35421b12: Follow RecyclerView API changes
* commit '35421b12299f9569f82c228631c4156fbb3f0b94': Follow RecyclerView API changes
This commit is contained in:
@@ -85,11 +85,10 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void layoutChildren(RecyclerView.Adapter adapter, RecyclerView.Recycler recycler) {
|
public void layoutChildren(RecyclerView.Adapter adapter, RecyclerView.Recycler recycler) {
|
||||||
final RecyclerView parent = getRecyclerView();
|
final int parentBottom = getHeight() - getPaddingBottom();
|
||||||
final int parentBottom = parent.getHeight() - parent.getPaddingBottom();
|
|
||||||
|
|
||||||
final View oldTopView = parent.getChildCount() > 0 ? parent.getChildAt(0) : null;
|
final View oldTopView = getChildCount() > 0 ? getChildAt(0) : null;
|
||||||
int oldTop = parent.getPaddingTop();
|
int oldTop = getPaddingTop();
|
||||||
if (oldTopView != null) {
|
if (oldTopView != null) {
|
||||||
oldTop = oldTopView.getTop();
|
oldTop = oldTopView.getTop();
|
||||||
}
|
}
|
||||||
@@ -98,12 +97,12 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
|
|
||||||
int top = oldTop;
|
int top = oldTop;
|
||||||
int bottom;
|
int bottom;
|
||||||
final int left = parent.getPaddingLeft();
|
final int left = getPaddingLeft();
|
||||||
final int right = parent.getWidth() - parent.getPaddingRight();
|
final int right = getWidth() - getPaddingRight();
|
||||||
|
|
||||||
final int count = adapter.getItemCount();
|
final int count = adapter.getItemCount();
|
||||||
for (int i = 0; mFirstPosition + i < count && top < parentBottom; i++, top = bottom) {
|
for (int i = 0; mFirstPosition + i < count && top < parentBottom; i++, top = bottom) {
|
||||||
View v = recycler.getViewForPosition(mFirstPosition + i);
|
View v = recycler.getViewForPosition(adapter, mFirstPosition + i);
|
||||||
addView(v, i);
|
addView(v, i);
|
||||||
v.measure(MeasureSpec.makeMeasureSpec(right - left, MeasureSpec.EXACTLY),
|
v.measure(MeasureSpec.makeMeasureSpec(right - left, MeasureSpec.EXACTLY),
|
||||||
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
||||||
@@ -126,25 +125,25 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler) {
|
public int scrollVerticallyBy(int dy, RecyclerView.Adapter adapter,
|
||||||
final RecyclerView parent = getRecyclerView();
|
RecyclerView.Recycler recycler) {
|
||||||
if (parent.getChildCount() == 0) {
|
if (getChildCount() == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int scrolled = 0;
|
int scrolled = 0;
|
||||||
final int left = parent.getPaddingLeft();
|
final int left = getPaddingLeft();
|
||||||
final int right = parent.getWidth() - parent.getPaddingRight();
|
final int right = getWidth() - getPaddingRight();
|
||||||
if (dy < 0) {
|
if (dy < 0) {
|
||||||
while (scrolled > dy) {
|
while (scrolled > dy) {
|
||||||
final View topView = parent.getChildAt(0);
|
final View topView = getChildAt(0);
|
||||||
final int hangingTop = Math.max(-topView.getTop(), 0);
|
final int hangingTop = Math.max(-topView.getTop(), 0);
|
||||||
final int scrollBy = Math.min(scrolled - dy, hangingTop);
|
final int scrollBy = Math.min(scrolled - dy, hangingTop);
|
||||||
scrolled -= scrollBy;
|
scrolled -= scrollBy;
|
||||||
parent.offsetChildrenVertical(scrollBy);
|
offsetChildrenVertical(scrollBy);
|
||||||
if (mFirstPosition > 0 && scrolled > dy) {
|
if (mFirstPosition > 0 && scrolled > dy) {
|
||||||
mFirstPosition--;
|
mFirstPosition--;
|
||||||
View v = recycler.getViewForPosition(mFirstPosition);
|
View v = recycler.getViewForPosition(adapter, mFirstPosition);
|
||||||
addView(v, 0);
|
addView(v, 0);
|
||||||
v.measure(MeasureSpec.makeMeasureSpec(right - left, MeasureSpec.EXACTLY),
|
v.measure(MeasureSpec.makeMeasureSpec(right - left, MeasureSpec.EXACTLY),
|
||||||
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
||||||
@@ -156,18 +155,17 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (dy > 0) {
|
} else if (dy > 0) {
|
||||||
final int parentHeight = parent.getHeight();
|
final int parentHeight = getHeight();
|
||||||
while (scrolled < dy) {
|
while (scrolled < dy) {
|
||||||
final View bottomView = parent.getChildAt(parent.getChildCount() - 1);
|
final View bottomView = getChildAt(getChildCount() - 1);
|
||||||
final int hangingBottom = Math.max(bottomView.getBottom() - parentHeight, 0);
|
final int hangingBottom = Math.max(bottomView.getBottom() - parentHeight, 0);
|
||||||
final int scrollBy = -Math.min(dy - scrolled, hangingBottom);
|
final int scrollBy = -Math.min(dy - scrolled, hangingBottom);
|
||||||
scrolled -= scrollBy;
|
scrolled -= scrollBy;
|
||||||
parent.offsetChildrenVertical(scrollBy);
|
offsetChildrenVertical(scrollBy);
|
||||||
if (scrolled < dy &&
|
if (scrolled < dy && getItemCount() > mFirstPosition + getChildCount()) {
|
||||||
parent.getAdapter().getItemCount() > mFirstPosition + parent.getChildCount()) {
|
View v = recycler.getViewForPosition(adapter,
|
||||||
View v = recycler.getViewForPosition(
|
mFirstPosition + getChildCount());
|
||||||
mFirstPosition + parent.getChildCount());
|
final int top = getChildAt(getChildCount() - 1).getBottom();
|
||||||
final int top = parent.getChildAt(parent.getChildCount() - 1).getBottom();
|
|
||||||
addView(v);
|
addView(v);
|
||||||
v.measure(MeasureSpec.makeMeasureSpec(right - left, MeasureSpec.EXACTLY),
|
v.measure(MeasureSpec.makeMeasureSpec(right - left, MeasureSpec.EXACTLY),
|
||||||
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
||||||
@@ -184,25 +182,23 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onFocusSearchFailed(View focused, int direction,
|
public View onFocusSearchFailed(View focused, int direction,
|
||||||
RecyclerView.Recycler recycler) {
|
RecyclerView.Adapter adapter, RecyclerView.Recycler recycler) {
|
||||||
final RecyclerView rv = getRecyclerView();
|
final int oldCount = getChildCount();
|
||||||
final int oldFirstPosition = mFirstPosition;
|
|
||||||
final int oldCount = rv.getChildCount();
|
|
||||||
|
|
||||||
if (oldCount == 0) {
|
if (oldCount == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int left = rv.getPaddingLeft();
|
final int left = getPaddingLeft();
|
||||||
final int right = rv.getWidth() - rv.getPaddingRight();
|
final int right = getWidth() - getPaddingRight();
|
||||||
|
|
||||||
View toFocus = null;
|
View toFocus = null;
|
||||||
int newViewsHeight = 0;
|
int newViewsHeight = 0;
|
||||||
if (direction == View.FOCUS_UP || direction == View.FOCUS_BACKWARD) {
|
if (direction == View.FOCUS_UP || direction == View.FOCUS_BACKWARD) {
|
||||||
while (mFirstPosition > 0 && newViewsHeight < mScrollDistance) {
|
while (mFirstPosition > 0 && newViewsHeight < mScrollDistance) {
|
||||||
mFirstPosition--;
|
mFirstPosition--;
|
||||||
View v = recycler.getViewForPosition(mFirstPosition);
|
View v = recycler.getViewForPosition(adapter, mFirstPosition);
|
||||||
final int bottom = rv.getChildAt(0).getTop(); // TODO decorated top?
|
final int bottom = getChildAt(0).getTop(); // TODO decorated top?
|
||||||
addView(v, 0);
|
addView(v, 0);
|
||||||
v.measure(MeasureSpec.makeMeasureSpec(right - left, MeasureSpec.EXACTLY),
|
v.measure(MeasureSpec.makeMeasureSpec(right - left, MeasureSpec.EXACTLY),
|
||||||
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
||||||
@@ -215,10 +211,10 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (direction == View.FOCUS_DOWN || direction == View.FOCUS_FORWARD) {
|
if (direction == View.FOCUS_DOWN || direction == View.FOCUS_FORWARD) {
|
||||||
while (mFirstPosition + rv.getChildCount() < rv.getAdapter().getItemCount() &&
|
while (mFirstPosition + getChildCount() < getItemCount() &&
|
||||||
newViewsHeight < mScrollDistance) {
|
newViewsHeight < mScrollDistance) {
|
||||||
View v = recycler.getViewForPosition(mFirstPosition + rv.getChildCount());
|
View v = recycler.getViewForPosition(adapter, mFirstPosition + getChildCount());
|
||||||
final int top = rv.getChildAt(rv.getChildCount() - 1).getBottom();
|
final int top = getChildAt(getChildCount() - 1).getBottom();
|
||||||
addView(v);
|
addView(v);
|
||||||
v.measure(MeasureSpec.makeMeasureSpec(right - left, MeasureSpec.EXACTLY),
|
v.measure(MeasureSpec.makeMeasureSpec(right - left, MeasureSpec.EXACTLY),
|
||||||
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
||||||
@@ -235,15 +231,14 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void detachAndScrapViewsOutOfBounds(RecyclerView.Recycler recycler) {
|
public void detachAndScrapViewsOutOfBounds(RecyclerView.Recycler recycler) {
|
||||||
final RecyclerView parent = getRecyclerView();
|
final int childCount = getChildCount();
|
||||||
final int childCount = parent.getChildCount();
|
final int parentWidth = getWidth();
|
||||||
final int parentWidth = parent.getWidth();
|
final int parentHeight = getHeight();
|
||||||
final int parentHeight = parent.getHeight();
|
|
||||||
boolean foundFirst = false;
|
boolean foundFirst = false;
|
||||||
int first = 0;
|
int first = 0;
|
||||||
int last = 0;
|
int last = 0;
|
||||||
for (int i = 0; i < childCount; i++) {
|
for (int i = 0; i < childCount; i++) {
|
||||||
final View v = parent.getChildAt(i);
|
final View v = getChildAt(i);
|
||||||
if (v.hasFocus() || (v.getRight() >= 0 && v.getLeft() <= parentWidth &&
|
if (v.hasFocus() || (v.getRight() >= 0 && v.getLeft() <= parentWidth &&
|
||||||
v.getBottom() >= 0 && v.getTop() <= parentHeight)) {
|
v.getBottom() >= 0 && v.getTop() <= parentHeight)) {
|
||||||
if (!foundFirst) {
|
if (!foundFirst) {
|
||||||
@@ -254,12 +249,12 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = childCount - 1; i > last; i--) {
|
for (int i = childCount - 1; i > last; i--) {
|
||||||
recycler.detachAndScrapView(parent.getChildAt(i));
|
recycler.detachAndScrapView(getChildAt(i));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < first; i++) {
|
for (int i = first - 1; i >= 0; i--) {
|
||||||
recycler.detachAndScrapView(parent.getChildAt(i));
|
recycler.detachAndScrapView(getChildAt(i));
|
||||||
}
|
}
|
||||||
if (parent.getChildCount() == 0) {
|
if (getChildCount() == 0) {
|
||||||
mFirstPosition = 0;
|
mFirstPosition = 0;
|
||||||
} else {
|
} else {
|
||||||
mFirstPosition += first;
|
mFirstPosition += first;
|
||||||
@@ -276,7 +271,7 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
RecyclerViewActivity.this.getTheme().resolveAttribute(
|
RecyclerViewActivity.this.getTheme().resolveAttribute(
|
||||||
R.attr.selectableItemBackground, val, true);
|
R.attr.selectableItemBackground, val, true);
|
||||||
mBackground = val.resourceId;
|
mBackground = val.resourceId;
|
||||||
mValues = new ArrayList();
|
mValues = new ArrayList<String>();
|
||||||
Collections.addAll(mValues, strings);
|
Collections.addAll(mValues, strings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user