Remove deprecated RecyclerView methods
Change-Id: If9b0aca85221d64dbbb5cda75f985a91de6c67d2
(cherry picked from commit 67bdb44d98)
This commit is contained in:
@@ -92,8 +92,7 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
public void checkboxClicked(View view) {
|
public void checkboxClicked(View view) {
|
||||||
ViewGroup parent = (ViewGroup) view.getParent();
|
ViewGroup parent = (ViewGroup) view.getParent();
|
||||||
boolean selected = ((CheckBox) view).isChecked();
|
boolean selected = ((CheckBox) view).isChecked();
|
||||||
int index = mRecyclerView.indexOfChild(parent);
|
MyViewHolder holder = (MyViewHolder) mRecyclerView.getChildViewHolder(parent);
|
||||||
MyViewHolder holder = (MyViewHolder) mRecyclerView.getViewHolderForChildAt(index);
|
|
||||||
mAdapter.selectItem(holder, selected);
|
mAdapter.selectItem(holder, selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,8 +163,7 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLayoutChildren(RecyclerView.Adapter adapter, RecyclerView.Recycler recycler,
|
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||||
boolean structureChanged, RecyclerView.State state) {
|
|
||||||
int parentBottom = getHeight() - getPaddingBottom();
|
int parentBottom = getHeight() - getPaddingBottom();
|
||||||
|
|
||||||
final View oldTopView = getChildCount() > 0 ? getChildAt(0) : null;
|
final View oldTopView = getChildCount() > 0 ? getChildAt(0) : null;
|
||||||
@@ -185,7 +183,7 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
|
|
||||||
int count = state.getItemCount();
|
int count = state.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(adapter, mFirstPosition + i);
|
View v = recycler.getViewForPosition(mFirstPosition + i);
|
||||||
|
|
||||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) v.getLayoutParams();
|
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) v.getLayoutParams();
|
||||||
if (!params.isItemRemoved()) {
|
if (!params.isItemRemoved()) {
|
||||||
@@ -242,8 +240,8 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int scrollVerticallyBy(int dy, RecyclerView.Adapter adapter,
|
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler,
|
||||||
RecyclerView.Recycler recycler) {
|
RecyclerView.State state) {
|
||||||
if (getChildCount() == 0) {
|
if (getChildCount() == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -260,7 +258,7 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
offsetChildrenVertical(scrollBy);
|
offsetChildrenVertical(scrollBy);
|
||||||
if (mFirstPosition > 0 && scrolled > dy) {
|
if (mFirstPosition > 0 && scrolled > dy) {
|
||||||
mFirstPosition--;
|
mFirstPosition--;
|
||||||
View v = recycler.getViewForPosition(adapter, mFirstPosition);
|
View v = recycler.getViewForPosition(mFirstPosition);
|
||||||
addView(v, 0);
|
addView(v, 0);
|
||||||
measureChild(v, 0, 0);
|
measureChild(v, 0, 0);
|
||||||
final int bottom = topView.getTop(); // TODO decorated top?
|
final int bottom = topView.getTop(); // TODO decorated top?
|
||||||
@@ -279,8 +277,7 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
scrolled -= scrollBy;
|
scrolled -= scrollBy;
|
||||||
offsetChildrenVertical(scrollBy);
|
offsetChildrenVertical(scrollBy);
|
||||||
if (scrolled < dy && getItemCount() > mFirstPosition + getChildCount()) {
|
if (scrolled < dy && getItemCount() > mFirstPosition + getChildCount()) {
|
||||||
View v = recycler.getViewForPosition(adapter,
|
View v = recycler.getViewForPosition(mFirstPosition + getChildCount());
|
||||||
mFirstPosition + getChildCount());
|
|
||||||
final int top = getChildAt(getChildCount() - 1).getBottom();
|
final int top = getChildAt(getChildCount() - 1).getBottom();
|
||||||
addView(v);
|
addView(v);
|
||||||
measureChild(v, 0, 0);
|
measureChild(v, 0, 0);
|
||||||
@@ -297,7 +294,7 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onFocusSearchFailed(View focused, int direction,
|
public View onFocusSearchFailed(View focused, int direction,
|
||||||
RecyclerView.Adapter adapter, RecyclerView.Recycler recycler) {
|
RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||||
final int oldCount = getChildCount();
|
final int oldCount = getChildCount();
|
||||||
|
|
||||||
if (oldCount == 0) {
|
if (oldCount == 0) {
|
||||||
@@ -312,7 +309,7 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
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(adapter, mFirstPosition);
|
View v = recycler.getViewForPosition(mFirstPosition);
|
||||||
final int bottom = getChildAt(0).getTop(); // TODO decorated top?
|
final int bottom = getChildAt(0).getTop(); // TODO decorated top?
|
||||||
addView(v, 0);
|
addView(v, 0);
|
||||||
measureChild(v, 0, 0);
|
measureChild(v, 0, 0);
|
||||||
@@ -327,7 +324,7 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
if (direction == View.FOCUS_DOWN || direction == View.FOCUS_FORWARD) {
|
if (direction == View.FOCUS_DOWN || direction == View.FOCUS_FORWARD) {
|
||||||
while (mFirstPosition + getChildCount() < getItemCount() &&
|
while (mFirstPosition + getChildCount() < getItemCount() &&
|
||||||
newViewsHeight < mScrollDistance) {
|
newViewsHeight < mScrollDistance) {
|
||||||
View v = recycler.getViewForPosition(adapter, mFirstPosition + getChildCount());
|
View v = recycler.getViewForPosition(mFirstPosition + getChildCount());
|
||||||
final int top = getChildAt(getChildCount() - 1).getBottom();
|
final int top = getChildAt(getChildCount() - 1).getBottom();
|
||||||
addView(v);
|
addView(v);
|
||||||
measureChild(v, 0, 0);
|
measureChild(v, 0, 0);
|
||||||
|
|||||||
@@ -102,16 +102,8 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLayoutChildren(RecyclerView.Adapter adapter, RecyclerView.Recycler recycler,
|
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||||
boolean structureChanged, RecyclerView.State state) {
|
|
||||||
layoutChildren(adapter, recycler, structureChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void layoutChildren(RecyclerView.Adapter adapter, RecyclerView.Recycler recycler,
|
|
||||||
boolean structureChanged) {
|
|
||||||
final int parentBottom = getHeight() - getPaddingBottom();
|
final int parentBottom = getHeight() - getPaddingBottom();
|
||||||
|
|
||||||
final View oldTopView = getChildCount() > 0 ? getChildAt(0) : null;
|
final View oldTopView = getChildCount() > 0 ? getChildAt(0) : null;
|
||||||
int oldTop = getPaddingTop();
|
int oldTop = getPaddingTop();
|
||||||
if (oldTopView != null) {
|
if (oldTopView != null) {
|
||||||
@@ -125,16 +117,14 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
final int left = getPaddingLeft();
|
final int left = getPaddingLeft();
|
||||||
final int right = getWidth() - getPaddingRight();
|
final int right = getWidth() - getPaddingRight();
|
||||||
|
|
||||||
final int count = adapter.getItemCount();
|
final int count = state.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(adapter, mFirstPosition + i);
|
View v = recycler.getViewForPosition(mFirstPosition + i);
|
||||||
addView(v, i);
|
addView(v, i);
|
||||||
measureChildWithMargins(v, 0, 0);
|
measureChildWithMargins(v, 0, 0);
|
||||||
bottom = top + getDecoratedMeasuredHeight(v);
|
bottom = top + getDecoratedMeasuredHeight(v);
|
||||||
layoutDecorated(v, left, top, right, bottom);
|
layoutDecorated(v, left, top, right, bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeAndRecycleScrap(recycler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -149,8 +139,8 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int scrollVerticallyBy(int dy, RecyclerView.Adapter adapter,
|
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler,
|
||||||
RecyclerView.Recycler recycler) {
|
RecyclerView.State state) {
|
||||||
if (getChildCount() == 0) {
|
if (getChildCount() == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -167,7 +157,7 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
offsetChildrenVertical(scrollBy);
|
offsetChildrenVertical(scrollBy);
|
||||||
if (mFirstPosition > 0 && scrolled > dy) {
|
if (mFirstPosition > 0 && scrolled > dy) {
|
||||||
mFirstPosition--;
|
mFirstPosition--;
|
||||||
View v = recycler.getViewForPosition(adapter, mFirstPosition);
|
View v = recycler.getViewForPosition(mFirstPosition);
|
||||||
addView(v, 0);
|
addView(v, 0);
|
||||||
measureChildWithMargins(v, 0, 0);
|
measureChildWithMargins(v, 0, 0);
|
||||||
final int bottom = getDecoratedTop(topView);
|
final int bottom = getDecoratedTop(topView);
|
||||||
@@ -187,8 +177,7 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
scrolled -= scrollBy;
|
scrolled -= scrollBy;
|
||||||
offsetChildrenVertical(scrollBy);
|
offsetChildrenVertical(scrollBy);
|
||||||
if (scrolled < dy && getItemCount() > mFirstPosition + getChildCount()) {
|
if (scrolled < dy && getItemCount() > mFirstPosition + getChildCount()) {
|
||||||
View v = recycler.getViewForPosition(adapter,
|
View v = recycler.getViewForPosition(mFirstPosition + getChildCount());
|
||||||
mFirstPosition + getChildCount());
|
|
||||||
final int top = getDecoratedBottom(getChildAt(getChildCount() - 1));
|
final int top = getDecoratedBottom(getChildAt(getChildCount() - 1));
|
||||||
addView(v);
|
addView(v);
|
||||||
measureChildWithMargins(v, 0, 0);
|
measureChildWithMargins(v, 0, 0);
|
||||||
@@ -205,7 +194,7 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onFocusSearchFailed(View focused, int direction,
|
public View onFocusSearchFailed(View focused, int direction,
|
||||||
RecyclerView.Adapter adapter, RecyclerView.Recycler recycler) {
|
RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||||
final int oldCount = getChildCount();
|
final int oldCount = getChildCount();
|
||||||
|
|
||||||
if (oldCount == 0) {
|
if (oldCount == 0) {
|
||||||
@@ -220,7 +209,7 @@ public class RecyclerViewActivity extends Activity {
|
|||||||
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(adapter, mFirstPosition);
|
View v = recycler.getViewForPosition(mFirstPosition);
|
||||||
final int bottom = getDecoratedTop(getChildAt(0));
|
final int bottom = getDecoratedTop(getChildAt(0));
|
||||||
addView(v, 0);
|
addView(v, 0);
|
||||||
measureChildWithMargins(v, 0, 0);
|
measureChildWithMargins(v, 0, 0);
|
||||||
@@ -235,7 +224,7 @@ 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 + getChildCount() < getItemCount() &&
|
while (mFirstPosition + getChildCount() < getItemCount() &&
|
||||||
newViewsHeight < mScrollDistance) {
|
newViewsHeight < mScrollDistance) {
|
||||||
View v = recycler.getViewForPosition(adapter, mFirstPosition + getChildCount());
|
View v = recycler.getViewForPosition(mFirstPosition + getChildCount());
|
||||||
final int top = getDecoratedBottom(getChildAt(getChildCount() - 1));
|
final int top = getDecoratedBottom(getChildAt(getChildCount() - 1));
|
||||||
addView(v);
|
addView(v);
|
||||||
measureChildWithMargins(v, 0, 0);
|
measureChildWithMargins(v, 0, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user