use of android.support.v7.widget.helper.ItemTouchHelper.END in project vlayout by alibaba.
the class StickyLayoutHelper method layoutViews.
@Override
public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper) {
// reach the end of this layout
if (isOutOfRange(layoutState.getCurrentPosition())) {
return;
}
// find view in currentPosition
View view = mFixView;
if (view == null) {
view = layoutState.next(recycler);
} else {
layoutState.skipCurrentPosition();
}
if (view == null) {
result.mFinished = true;
return;
}
doMeasure(view, helper);
// do layout
final boolean layoutInVertical = helper.getOrientation() == VERTICAL;
final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
result.mConsumed = orientationHelper.getDecoratedMeasurement(view);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
// Do normal measure&layout phase by default
mDoNormalHandle = true;
final int remainingSpace = layoutState.getAvailable() - result.mConsumed + layoutState.getExtra();
int left, top, right, bottom;
if (helper.getOrientation() == VERTICAL) {
// not support RTL now
if (helper.isDoLayoutRTL()) {
right = helper.getContentWidth() - helper.getPaddingRight() - mMarginRight;
left = right - orientationHelper.getDecoratedMeasurementInOther(view);
} else {
left = helper.getPaddingLeft() + mMarginLeft;
right = left + orientationHelper.getDecoratedMeasurementInOther(view);
}
// whether this layout pass is layout to start or to end
if (layoutState.getLayoutDirection() == LayoutStateWrapper.LAYOUT_START) {
// fill start, from bottom to top
bottom = layoutState.getOffset() - mMarginBottom;
top = layoutState.getOffset() - result.mConsumed;
} else {
// fill end, from top to bottom
if (mStickyStart) {
top = layoutState.getOffset() + mMarginTop;
bottom = layoutState.getOffset() + result.mConsumed;
} else {
bottom = orientationHelper.getEndAfterPadding() - mMarginBottom - mOffset - mAdjuster.bottom;
top = bottom - result.mConsumed;
}
}
if (helper.getReverseLayout() || !mStickyStart) {
if ((remainingSpace < (mOffset + mAdjuster.bottom) && layoutState.getItemDirection() == LayoutStateWrapper.ITEM_DIRECTION_TAIL) || (bottom > mMarginBottom + mOffset + mAdjuster.bottom)) {
mDoNormalHandle = false;
mFixView = view;
bottom = orientationHelper.getEndAfterPadding() - mMarginBottom - mOffset - mAdjuster.bottom;
top = bottom - result.mConsumed;
}
} else {
// should not use 0
if ((remainingSpace < (mOffset + mAdjuster.top) && layoutState.getItemDirection() == LayoutStateWrapper.ITEM_DIRECTION_HEAD) || (top < mMarginTop + mOffset + mAdjuster.top)) {
mDoNormalHandle = false;
mFixView = view;
top = orientationHelper.getStartAfterPadding() + mMarginTop + mOffset + mAdjuster.top;
bottom = top + result.mConsumed;
} else {
if (VirtualLayoutManager.sDebuggable) {
Log.i("Sticky", "remainingSpace: " + remainingSpace + " offset: " + mOffset);
}
}
}
} else {
top = helper.getPaddingTop();
bottom = top + orientationHelper.getDecoratedMeasurementInOther(view) + mMarginTop;
if (layoutState.getLayoutDirection() == LayoutStateWrapper.LAYOUT_START) {
right = layoutState.getOffset() - mMarginRight;
left = layoutState.getOffset() - result.mConsumed;
} else {
left = layoutState.getOffset() + mMarginLeft;
right = layoutState.getOffset() + result.mConsumed;
}
if (helper.getReverseLayout() || !mStickyStart) {
if (remainingSpace < mOffset + mAdjuster.right) {
mDoNormalHandle = false;
mFixView = view;
right = orientationHelper.getEndAfterPadding() - mOffset - mAdjuster.right;
left = right - result.mConsumed;
}
} else {
if (remainingSpace < mOffset + mAdjuster.left) {
mDoNormalHandle = false;
mFixView = view;
left = orientationHelper.getStartAfterPadding() + mOffset + mAdjuster.left;
right = result.mConsumed;
}
}
}
layoutChildWithMargin(view, left, top, right, bottom, helper);
result.mConsumed += (layoutInVertical ? getVerticalMargin() : getHorizontalMargin());
if (state.isPreLayout()) {
mDoNormalHandle = true;
}
if (mDoNormalHandle) {
helper.addChildView(layoutState, view);
handleStateOnResult(result, view);
} else {
// result.mConsumed += mOffset;
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project NoteText by ViWu.
the class EditCard method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_card);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionbar = getSupportActionBar();
MainMenu.initializeToolbar(toolbar, actionbar);
// get Intent from MainActivity
final Intent editIntent = getIntent();
setName = editIntent.getStringExtra("setName");
// set edit text boxes if questions and answers are already saved
EditText questionSet = (EditText) findViewById(R.id.questionField);
if (questionSet != null) {
String str = editIntent.getStringExtra("questions");
questionSet.setText(str);
// initialize cursor position to end of string
int cursorPos = str.length();
questionSet.setSelection(cursorPos);
}
EditText answerSet = (EditText) findViewById(R.id.answerField);
if (answerSet != null) {
String str = editIntent.getStringExtra("answers");
answerSet.setText(str);
}
// if cancel button is clicked, go back to main activity
Button cancelButton = (Button) findViewById(R.id.cancel);
if (cancelButton != null) {
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
intent = new Intent(EditCard.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
finish();
}
});
}
// if ok button is clicked, save the questions and answers fields, then go back to main activity
Button OkButton = (Button) findViewById(R.id.ok);
if (OkButton != null) {
OkButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText questionBox = (EditText) findViewById(R.id.questionField);
EditText answerBox = (EditText) findViewById(R.id.answerField);
assert questionBox != null;
assert answerBox != null;
String answer = answerBox.getText().toString();
String question = questionBox.getText().toString();
answer = answer.replace('\n', ' ');
question = question.replace('\n', ' ');
int pos = editIntent.getIntExtra("position", 0);
MainActivity.setAnswers(pos, answer);
MainActivity.setQuestions(pos, question);
fileWrite();
MainActivity.refreshAdapter();
intent = new Intent(EditCard.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
finish();
}
});
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project XRecyclerView by jianghejie.
the class AlphaChangeActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alpha_change_layout);
mRecyclerView = (XRecyclerView) this.findViewById(R.id.recyclerview);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);
/**
* ----- alpha change listen test start -----
*/
final RelativeLayout alpha_title = (RelativeLayout) findViewById(R.id.alpha_title);
findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
findViewById(R.id.back_to_top).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mRecyclerView.scrollToPosition(0);
}
});
mRecyclerView.setScrollAlphaChangeListener(new XRecyclerView.ScrollAlphaChangeListener() {
@Override
public void onAlphaChange(int alpha) {
alpha_title.getBackground().setAlpha(alpha);
}
@Override
public int setLimitHeight() {
return 1300;
}
});
/**
* ------ alpha change listen test end -----
*/
mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
@Override
public void onRefresh() {
refreshTime++;
times = 0;
new Handler().postDelayed(new Runnable() {
public void run() {
listData.clear();
for (int i = 0; i < 15; i++) {
listData.add("item" + i + "after " + refreshTime + " times of refresh");
}
mAdapter.notifyDataSetChanged();
mRecyclerView.refreshComplete();
}
}, // refresh data here
1000);
}
@Override
public void onLoadMore() {
if (times < 2) {
new Handler().postDelayed(new Runnable() {
public void run() {
for (int i = 0; i < 15; i++) {
listData.add("item" + (1 + listData.size()));
}
mRecyclerView.loadMoreComplete();
mAdapter.notifyDataSetChanged();
}
}, 1000);
} else {
new Handler().postDelayed(new Runnable() {
public void run() {
for (int i = 0; i < 9; i++) {
listData.add("item" + (1 + listData.size()));
}
mRecyclerView.setNoMore(true);
mAdapter.notifyDataSetChanged();
}
}, 1000);
}
times++;
}
});
listData = new ArrayList<String>();
mAdapter = new MyAdapter(listData);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.refresh();
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project EasyRecyclerView by Jude95.
the class DividerDecoration method onDraw.
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
if (parent.getAdapter() == null) {
return;
}
int orientation = 0;
int headerCount = 0, footerCount = 0, dataCount;
if (parent.getAdapter() instanceof RecyclerArrayAdapter) {
headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount();
footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount();
dataCount = ((RecyclerArrayAdapter) parent.getAdapter()).getCount();
} else {
dataCount = parent.getAdapter().getItemCount();
}
int dataStartPosition = headerCount;
int dataEndPosition = headerCount + dataCount;
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof StaggeredGridLayoutManager) {
orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
} else if (layoutManager instanceof GridLayoutManager) {
orientation = ((GridLayoutManager) layoutManager).getOrientation();
} else if (layoutManager instanceof LinearLayoutManager) {
orientation = ((LinearLayoutManager) layoutManager).getOrientation();
}
int start, end;
if (orientation == OrientationHelper.VERTICAL) {
start = parent.getPaddingLeft() + mPaddingLeft;
end = parent.getWidth() - parent.getPaddingRight() - mPaddingRight;
} else {
start = parent.getPaddingTop() + mPaddingLeft;
end = parent.getHeight() - parent.getPaddingBottom() - mPaddingRight;
}
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
int position = parent.getChildAdapterPosition(child);
if (// 数据项除了最后一项
position >= dataStartPosition && position < dataEndPosition - 1 || // 数据项最后一项
(position == dataEndPosition - 1 && mDrawLastItem) || // header&footer且可绘制
(!(position >= dataStartPosition && position < dataEndPosition) && mDrawHeaderFooter)) {
if (orientation == OrientationHelper.VERTICAL) {
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int top = child.getBottom() + params.bottomMargin;
int bottom = top + mHeight;
mColorDrawable.setBounds(start, top, end, bottom);
mColorDrawable.draw(c);
} else {
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int left = child.getRight() + params.rightMargin;
int right = left + mHeight;
mColorDrawable.setBounds(left, start, right, end);
mColorDrawable.draw(c);
}
}
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project ChipsLayoutManager by BelooS.
the class ChipsLayoutManager method fillWithLayouter.
/**
* place views in layout started from chosen position with chosen layouter
*/
private void fillWithLayouter(RecyclerView.Recycler recycler, ILayouter layouter, int startingPos) {
if (startingPos < 0)
return;
AbstractPositionIterator iterator = layouter.positionIterator();
iterator.move(startingPos);
while (iterator.hasNext()) {
int pos = iterator.next();
View view = viewCache.get(pos);
if (view == null) {
// we don't have view from previous layouter stage, request new one
try {
view = recycler.getViewForPosition(pos);
} catch (IndexOutOfBoundsException e) {
/* WTF sometimes on prediction animation playing in case very fast sequential changes in adapter
* {@link #getItemCount} could return value bigger than real count of items
* & {@link RecyclerView.Recycler#getViewForPosition(int)} throws exception in this case!
* to handle it, just leave the loop*/
break;
}
logger.onItemRequested();
if (!layouter.placeView(view)) {
/* reached end of visible bounds, exit.
recycle view, which was requested previously
*/
recycler.recycleView(view);
logger.onItemRecycled();
break;
}
} else {
// we have detached views from previous layouter stage, attach it if needed
if (!layouter.onAttachView(view)) {
break;
}
// remove reattached view from cache
viewCache.remove(pos);
}
}
logger.onFinishedLayouter();
// layout last row, in case iterator fully processed
layouter.layoutRow();
}
Aggregations