Methods Summary |
---|
void | addView(android.view.View child, boolean hidden)Adds a view to the ViewGroup
addView(child, -1, hidden);
|
void | addView(android.view.View child, int index, boolean hidden)Add a view to the ViewGroup at an index
final int offset;
if (index < 0) {
offset = mCallback.getChildCount();
} else {
offset = getOffset(index);
}
mCallback.addView(child, offset);
mBucket.insert(offset, hidden);
if (hidden) {
mHiddenViews.add(child);
}
if (DEBUG) {
Log.d(TAG, "addViewAt " + index + ",h:" + hidden + ", " + this);
}
|
void | attachViewToParent(android.view.View child, int index, ViewGroup.LayoutParams layoutParams, boolean hidden)Attaches the provided view to the underlying ViewGroup.
final int offset;
if (index < 0) {
offset = mCallback.getChildCount();
} else {
offset = getOffset(index);
}
mCallback.attachViewToParent(child, offset, layoutParams);
mBucket.insert(offset, hidden);
if (hidden) {
mHiddenViews.add(child);
}
if (DEBUG) {
Log.d(TAG, "attach view to parent index:" + index + ",off:" + offset + "," +
"h:" + hidden + ", " + this);
}
|
void | detachViewFromParent(int index)Detaches the view at the provided index.
final int offset = getOffset(index);
mCallback.detachViewFromParent(offset);
mBucket.remove(offset);
if (DEBUG) {
Log.d(TAG, "detach view from parent " + index + ", off:" + offset);
}
|
android.view.View | findHiddenNonRemovedView(int position, int type)This can be used to find a disappearing view by position.
final int count = mHiddenViews.size();
for (int i = 0; i < count; i++) {
final View view = mHiddenViews.get(i);
RecyclerView.ViewHolder holder = mCallback.getChildViewHolder(view);
if (holder.getLayoutPosition() == position && !holder.isInvalid() &&
(type == RecyclerView.INVALID_TYPE || holder.getItemViewType() == type)) {
return view;
}
}
return null;
|
android.view.View | getChildAt(int index)Returns the child at provided index.
final int offset = getOffset(index);
return mCallback.getChildAt(offset);
|
int | getChildCount()Returns the number of children that are not hidden.
return mCallback.getChildCount() - mHiddenViews.size();
|
private int | getOffset(int index)
if (index < 0) {
return -1; //anything below 0 won't work as diff will be undefined.
}
final int limit = mCallback.getChildCount();
int offset = index;
while (offset < limit) {
final int removedBefore = mBucket.countOnesBefore(offset);
final int diff = index - (offset - removedBefore);
if (diff == 0) {
while (mBucket.get(offset)) { // ensure this offset is not hidden
offset ++;
}
return offset;
} else {
offset += diff;
}
}
return -1;
|
android.view.View | getUnfilteredChildAt(int index)Returns a child by ViewGroup offset. ChildHelper won't offset this index.
return mCallback.getChildAt(index);
|
int | getUnfilteredChildCount()Returns the total number of children.
return mCallback.getChildCount();
|
void | hide(android.view.View view)Marks a child view as hidden.
final int offset = mCallback.indexOfChild(view);
if (offset < 0) {
throw new IllegalArgumentException("view is not a child, cannot hide " + view);
}
if (DEBUG && mBucket.get(offset)) {
throw new RuntimeException("trying to hide same view twice, how come ? " + view);
}
mBucket.set(offset);
mHiddenViews.add(view);
if (DEBUG) {
Log.d(TAG, "hiding child " + view + " at offset " + offset+ ", " + this);
}
|
int | indexOfChild(android.view.View child)Returns the index of the child in regular perspective.
final int index = mCallback.indexOfChild(child);
if (index == -1) {
return -1;
}
if (mBucket.get(index)) {
if (DEBUG) {
throw new IllegalArgumentException("cannot get index of a hidden child");
} else {
return -1;
}
}
// reverse the index
return index - mBucket.countOnesBefore(index);
|
boolean | isHidden(android.view.View view)Returns whether a View is visible to LayoutManager or not.
return mHiddenViews.contains(view);
|
void | removeAllViewsUnfiltered()Removes all views from the ViewGroup including the hidden ones.
mCallback.removeAllViews();
mBucket.reset();
mHiddenViews.clear();
if (DEBUG) {
Log.d(TAG, "removeAllViewsUnfiltered");
}
|
void | removeView(android.view.View view)Removes the provided View from underlying RecyclerView.
int index = mCallback.indexOfChild(view);
if (index < 0) {
return;
}
mCallback.removeViewAt(index);
if (mBucket.remove(index)) {
mHiddenViews.remove(view);
}
if (DEBUG) {
Log.d(TAG, "remove View off:" + index + "," + this);
}
|
void | removeViewAt(int index)Removes the view at the provided index from RecyclerView.
final int offset = getOffset(index);
final View view = mCallback.getChildAt(offset);
if (view == null) {
return;
}
mCallback.removeViewAt(offset);
if (mBucket.remove(offset)) {
mHiddenViews.remove(view);
}
if (DEBUG) {
Log.d(TAG, "removeViewAt " + index + ", off:" + offset + ", " + this);
}
|
boolean | removeViewIfHidden(android.view.View view)Removes a view from the ViewGroup if it is hidden.
final int index = mCallback.indexOfChild(view);
if (index == -1) {
if (mHiddenViews.remove(view) && DEBUG) {
throw new IllegalStateException("view is in hidden list but not in view group");
}
return true;
}
if (mBucket.get(index)) {
mBucket.remove(index);
mCallback.removeViewAt(index);
if (!mHiddenViews.remove(view) && DEBUG) {
throw new IllegalStateException(
"removed a hidden view but it is not in hidden views list");
}
return true;
}
return false;
|
public java.lang.String | toString()
return mBucket.toString() + ", hidden list:" + mHiddenViews.size();
|