use of android.support.v7.widget.RecyclerView.Recycler in project DragTopLayout by chenupt.
the class RecyclerFragment method initViews.
private void initViews() {
RecyclerView recyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
// init recycler view
ModelRecyclerAdapter adapter = new ModelRecyclerAdapter(getActivity(), DataService.getInstance().getModelManager());
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(adapter);
// set data source
adapter.setList(DataService.getInstance().getList());
adapter.notifyDataSetChanged();
// attach top listener
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
EventBus.getDefault().post(AttachUtil.isRecyclerViewAttach(recyclerView));
}
});
}
use of android.support.v7.widget.RecyclerView.Recycler in project UltimateRecyclerView by cymcsg.
the class CustomLinearLayoutManager method measureScrapChild.
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec, int heightSpec, int[] measuredDimension) {
View view = recycler.getViewForPosition(position);
if (view != null) {
RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();
int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec, getPaddingLeft() + getPaddingRight(), p.width);
int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec, getPaddingTop() + getPaddingBottom(), p.height);
view.measure(childWidthSpec, childHeightSpec);
measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
recycler.recycleView(view);
}
}
use of android.support.v7.widget.RecyclerView.Recycler in project vlayout by alibaba.
the class ExposeLinearLayoutManagerEx method onLayoutChildren.
/**
* {@inheritDoc}
*/
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
// create layout state
if (DEBUG) {
Log.d(TAG, "is pre layout:" + state.isPreLayout());
}
if (mCurrentPendingSavedState != null && mCurrentPendingSavedState.getInt("AnchorPosition") >= 0) {
mCurrentPendingScrollPosition = mCurrentPendingSavedState.getInt("AnchorPosition");
}
ensureLayoutStateExpose();
mLayoutState.mRecycle = false;
// resolve layout direction
myResolveShouldLayoutReverse();
mAnchorInfo.reset();
mAnchorInfo.mLayoutFromEnd = mShouldReverseLayoutExpose ^ getStackFromEnd();
// calculate anchor position and coordinate
updateAnchorInfoForLayoutExpose(state, mAnchorInfo);
if (DEBUG) {
Log.d(TAG, "Anchor info:" + mAnchorInfo);
}
// LLM may decide to layout items for "extra" pixels to account for scrolling target,
// caching or predictive animations.
int extraForStart;
int extraForEnd;
final int extra = getExtraLayoutSpace(state);
boolean before = state.getTargetScrollPosition() < mAnchorInfo.mPosition;
if (before == mShouldReverseLayoutExpose) {
extraForEnd = extra;
extraForStart = 0;
} else {
extraForStart = extra;
extraForEnd = 0;
}
extraForStart += mOrientationHelper.getStartAfterPadding();
extraForEnd += mOrientationHelper.getEndPadding();
if (state.isPreLayout() && mCurrentPendingScrollPosition != RecyclerView.NO_POSITION && mPendingScrollPositionOffset != INVALID_OFFSET) {
// if the child is visible and we are going to move it around, we should layout
// extra items in the opposite direction to make sure new items animate nicely
// instead of just fading in
final View existing = findViewByPosition(mCurrentPendingScrollPosition);
if (existing != null) {
final int current;
final int upcomingOffset;
if (mShouldReverseLayoutExpose) {
current = mOrientationHelper.getEndAfterPadding() - mOrientationHelper.getDecoratedEnd(existing);
upcomingOffset = current - mPendingScrollPositionOffset;
} else {
current = mOrientationHelper.getDecoratedStart(existing) - mOrientationHelper.getStartAfterPadding();
upcomingOffset = mPendingScrollPositionOffset - current;
}
if (upcomingOffset > 0) {
extraForStart += upcomingOffset;
} else {
extraForEnd -= upcomingOffset;
}
}
}
int startOffset;
int endOffset;
onAnchorReady(state, mAnchorInfo);
detachAndScrapAttachedViews(recycler);
mLayoutState.mIsPreLayout = state.isPreLayout();
mLayoutState.mOnRefresLayout = true;
if (mAnchorInfo.mLayoutFromEnd) {
// fill towards start
updateLayoutStateToFillStartExpose(mAnchorInfo);
mLayoutState.mExtra = extraForStart;
fill(recycler, mLayoutState, state, false);
startOffset = mLayoutState.mOffset;
if (mLayoutState.mAvailable > 0) {
extraForEnd += mLayoutState.mAvailable;
}
// fill towards end
updateLayoutStateToFillEndExpose(mAnchorInfo);
mLayoutState.mExtra = extraForEnd;
mLayoutState.mCurrentPosition += mLayoutState.mItemDirection;
fill(recycler, mLayoutState, state, false);
endOffset = mLayoutState.mOffset;
} else {
// fill towards end
updateLayoutStateToFillEndExpose(mAnchorInfo);
mLayoutState.mExtra = extraForEnd;
fill(recycler, mLayoutState, state, false);
endOffset = mLayoutState.mOffset;
if (mLayoutState.mAvailable > 0) {
extraForStart += mLayoutState.mAvailable;
}
// fill towards start
updateLayoutStateToFillStartExpose(mAnchorInfo);
mLayoutState.mExtra = extraForStart;
mLayoutState.mCurrentPosition += mLayoutState.mItemDirection;
fill(recycler, mLayoutState, state, false);
startOffset = mLayoutState.mOffset;
}
// changed
if (getChildCount() > 0) {
// find which side we should check for gaps.
if (mShouldReverseLayoutExpose ^ getStackFromEnd()) {
int fixOffset = fixLayoutEndGapExpose(endOffset, recycler, state, true);
startOffset += fixOffset;
endOffset += fixOffset;
fixOffset = fixLayoutStartGapExpose(startOffset, recycler, state, false);
startOffset += fixOffset;
endOffset += fixOffset;
} else {
int fixOffset = fixLayoutStartGapExpose(startOffset, recycler, state, true);
startOffset += fixOffset;
endOffset += fixOffset;
fixOffset = fixLayoutEndGapExpose(endOffset, recycler, state, false);
startOffset += fixOffset;
endOffset += fixOffset;
}
}
layoutForPredictiveAnimationsExpose(recycler, state, startOffset, endOffset);
if (!state.isPreLayout()) {
mCurrentPendingScrollPosition = RecyclerView.NO_POSITION;
mPendingScrollPositionOffset = INVALID_OFFSET;
mOrientationHelper.onLayoutComplete();
}
mLastStackFromEnd = getStackFromEnd();
// we don't need this anymore
mCurrentPendingSavedState = null;
if (DEBUG) {
validateChildOrderExpose();
}
}
use of android.support.v7.widget.RecyclerView.Recycler in project vlayout by alibaba.
the class ExposeLinearLayoutManagerEx method layoutForPredictiveAnimationsExpose.
/**
* If necessary, layouts new items for predictive animations
*/
private void layoutForPredictiveAnimationsExpose(RecyclerView.Recycler recycler, RecyclerView.State state, int startOffset, int endOffset) {
// another view out of bounds.
if (!state.willRunPredictiveAnimations() || getChildCount() == 0 || state.isPreLayout() || !supportsPredictiveItemAnimations()) {
return;
}
// to make the logic simpler, we calculate the size of children and call fill.
int scrapExtraStart = 0, scrapExtraEnd = 0;
final List<RecyclerView.ViewHolder> scrapList = recycler.getScrapList();
final int scrapSize = scrapList.size();
final int firstChildPos = getPosition(getChildAt(0));
for (int i = 0; i < scrapSize; i++) {
RecyclerView.ViewHolder scrap = scrapList.get(i);
final int position = scrap.getPosition();
final int direction = position < firstChildPos != mShouldReverseLayoutExpose ? LayoutState.LAYOUT_START : LayoutState.LAYOUT_END;
if (direction == LayoutState.LAYOUT_START) {
scrapExtraStart += mOrientationHelper.getDecoratedMeasurement(scrap.itemView);
} else {
scrapExtraEnd += mOrientationHelper.getDecoratedMeasurement(scrap.itemView);
}
}
if (DEBUG) {
Log.d(TAG, "for unused scrap, decided to add " + scrapExtraStart + " towards start and " + scrapExtraEnd + " towards end");
}
mLayoutState.mScrapList = scrapList;
if (scrapExtraStart > 0) {
View anchor = getChildClosestToStartExpose();
updateLayoutStateToFillStartExpose(getPosition(anchor), startOffset);
mLayoutState.mExtra = scrapExtraStart;
mLayoutState.mAvailable = 0;
mLayoutState.mCurrentPosition += mShouldReverseLayoutExpose ? 1 : -1;
mLayoutState.mOnRefresLayout = true;
fill(recycler, mLayoutState, state, false);
}
if (scrapExtraEnd > 0) {
View anchor = getChildClosestToEndExpose();
updateLayoutStateToFillEndExpose(getPosition(anchor), endOffset);
mLayoutState.mExtra = scrapExtraEnd;
mLayoutState.mAvailable = 0;
mLayoutState.mCurrentPosition += mShouldReverseLayoutExpose ? -1 : 1;
mLayoutState.mOnRefresLayout = true;
fill(recycler, mLayoutState, state, false);
}
mLayoutState.mScrapList = null;
}
use of android.support.v7.widget.RecyclerView.Recycler in project vlayout by alibaba.
the class ExposeLinearLayoutManagerEx method onFocusSearchFailed.
@Override
public View onFocusSearchFailed(View focused, int focusDirection, RecyclerView.Recycler recycler, RecyclerView.State state) {
myResolveShouldLayoutReverse();
if (getChildCount() == 0) {
return null;
}
final int layoutDir = convertFocusDirectionToLayoutDirectionExpose(focusDirection);
if (layoutDir == LayoutState.INVALID_LAYOUT) {
return null;
}
View referenceChild = null;
if (layoutDir == LayoutState.LAYOUT_START) {
referenceChild = myFindReferenceChildClosestToStart(state);
} else {
referenceChild = myFindReferenceChildClosestToEnd(state);
}
if (referenceChild == null) {
if (DEBUG) {
Log.d(TAG, "Cannot find a child with a valid position to be used for focus search.");
}
return null;
}
ensureLayoutStateExpose();
final int maxScroll = (int) (MAX_SCROLL_FACTOR * mOrientationHelper.getTotalSpace());
updateLayoutStateExpose(layoutDir, maxScroll, false, state);
mLayoutState.mScrollingOffset = LayoutState.SCOLLING_OFFSET_NaN;
mLayoutState.mRecycle = false;
mLayoutState.mOnRefresLayout = false;
fill(recycler, mLayoutState, state, true);
final View nextFocus;
if (layoutDir == LayoutState.LAYOUT_START) {
nextFocus = getChildClosestToStartExpose();
} else {
nextFocus = getChildClosestToEndExpose();
}
if (nextFocus == referenceChild || !nextFocus.isFocusable()) {
return null;
}
return nextFocus;
}
Aggregations