use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project guanggoo-android by mzlogin.
the class TopicListFragment method initViews.
private void initViews() {
Context context = getContext();
final LinearLayoutManager layoutManager = new LinearLayoutManager(context);
mRecyclerView.setLayoutManager(layoutManager);
if (mAdapter == null) {
mAdapter = new TopicListAdapter(mListener);
}
mRecyclerView.setAdapter(mAdapter);
// ref https://stackoverflow.com/questions/26543131/how-to-implement-endless-list-with-recyclerview
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
// check for scroll down
if (dy > 0) {
visibleItemCount = layoutManager.getChildCount();
totalItemCount = layoutManager.getItemCount();
pastVisibleItems = layoutManager.findFirstVisibleItemPosition();
if (mLoadable) {
if ((visibleItemCount + pastVisibleItems) >= totalItemCount) {
mLoadable = false;
if (totalItemCount >= ConstantUtil.TOPICS_PER_PAGE && totalItemCount <= ConstantUtil.MAX_TOPICS) {
mPresenter.getMoreTopic(totalItemCount / ConstantUtil.TOPICS_PER_PAGE + 1);
} else {
Toast.makeText(getActivity(), "1024", Toast.LENGTH_SHORT).show();
}
}
}
}
}
});
initSwipeLayout(mRefreshLayout);
initSwipeLayout(mEmptyLayout);
handleEmptyList();
}
use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project guanggoo-android by mzlogin.
the class ReplyListFragment method initViews.
private void initViews() {
Context context = getContext();
final LinearLayoutManager layoutManager = new LinearLayoutManager(context);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.set(0, 0, 0, 1);
}
});
if (mAdapter == null) {
mAdapter = new ReplyListAdapter(mListener);
}
mRecyclerView.setAdapter(mAdapter);
// ref https://stackoverflow.com/questions/26543131/how-to-implement-endless-list-with-recyclerview
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
// check for scroll down
if (dy > 0) {
visibleItemCount = layoutManager.getChildCount();
totalItemCount = layoutManager.getItemCount();
pastVisibleItems = layoutManager.findFirstVisibleItemPosition();
if (mLoadable) {
if ((visibleItemCount + pastVisibleItems) >= totalItemCount) {
mLoadable = false;
if (totalItemCount >= ConstantUtil.REPLIES_PER_PAGE && totalItemCount <= ConstantUtil.MAX_TOPICS) {
mPresenter.getMoreReply(totalItemCount / ConstantUtil.REPLIES_PER_PAGE + 1);
} else {
Toast.makeText(getActivity(), "1024", Toast.LENGTH_SHORT).show();
}
}
}
}
}
});
initSwipeLayout(mRefreshLayout);
initSwipeLayout(mEmptyLayout);
handleEmptyList();
}
use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project superCleanMaster by joyoyao.
the class QuickReturnRecyclerViewOnScrollListener method onScrollStateChanged.
// endregion
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
// apply another list' s on scroll listener
for (RecyclerView.OnScrollListener listener : mExtraOnScrollListenerList) {
listener.onScrollStateChanged(recyclerView, newState);
}
if (newState == RecyclerView.SCROLL_STATE_IDLE && mCanSlideInIdleScrollState) {
int midHeader = -mMinHeaderTranslation / 2;
int midFooter = mMinFooterTranslation / 2;
switch(mQuickReturnType) {
case HEADER:
if (-mHeaderDiffTotal > 0 && -mHeaderDiffTotal < midHeader) {
ObjectAnimator anim = ObjectAnimator.ofFloat(mHeader, "translationY", mHeader.getTranslationY(), 0);
anim.setDuration(100);
anim.start();
mHeaderDiffTotal = 0;
} else if (-mHeaderDiffTotal < -mMinHeaderTranslation && -mHeaderDiffTotal >= midHeader) {
ObjectAnimator anim = ObjectAnimator.ofFloat(mHeader, "translationY", mHeader.getTranslationY(), mMinHeaderTranslation);
anim.setDuration(100);
anim.start();
mHeaderDiffTotal = mMinHeaderTranslation;
}
break;
case FOOTER:
if (-mFooterDiffTotal > 0 && -mFooterDiffTotal < midFooter) {
// slide up
ObjectAnimator anim = ObjectAnimator.ofFloat(mFooter, "translationY", mFooter.getTranslationY(), 0);
anim.setDuration(100);
anim.start();
mFooterDiffTotal = 0;
} else if (-mFooterDiffTotal < mMinFooterTranslation && -mFooterDiffTotal >= midFooter) {
// slide down
ObjectAnimator anim = ObjectAnimator.ofFloat(mFooter, "translationY", mFooter.getTranslationY(), mMinFooterTranslation);
anim.setDuration(100);
anim.start();
mFooterDiffTotal = -mMinFooterTranslation;
}
break;
case BOTH:
if (-mHeaderDiffTotal > 0 && -mHeaderDiffTotal < midHeader) {
ObjectAnimator anim = ObjectAnimator.ofFloat(mHeader, "translationY", mHeader.getTranslationY(), 0);
anim.setDuration(100);
anim.start();
mHeaderDiffTotal = 0;
} else if (-mHeaderDiffTotal < -mMinHeaderTranslation && -mHeaderDiffTotal >= midHeader) {
ObjectAnimator anim = ObjectAnimator.ofFloat(mHeader, "translationY", mHeader.getTranslationY(), mMinHeaderTranslation);
anim.setDuration(100);
anim.start();
mHeaderDiffTotal = mMinHeaderTranslation;
}
if (-mFooterDiffTotal > 0 && -mFooterDiffTotal < midFooter) {
// slide up
ObjectAnimator anim = ObjectAnimator.ofFloat(mFooter, "translationY", mFooter.getTranslationY(), 0);
anim.setDuration(100);
anim.start();
mFooterDiffTotal = 0;
} else if (-mFooterDiffTotal < mMinFooterTranslation && -mFooterDiffTotal >= midFooter) {
// slide down
ObjectAnimator anim = ObjectAnimator.ofFloat(mFooter, "translationY", mFooter.getTranslationY(), mMinFooterTranslation);
anim.setDuration(100);
anim.start();
mFooterDiffTotal = -mMinFooterTranslation;
}
break;
case TWITTER:
if (-mHeaderDiffTotal > 0 && -mHeaderDiffTotal < midHeader) {
ObjectAnimator anim = ObjectAnimator.ofFloat(mHeader, "translationY", mHeader.getTranslationY(), 0);
anim.setDuration(100);
anim.start();
mHeaderDiffTotal = 0;
} else if (-mHeaderDiffTotal < -mMinHeaderTranslation && -mHeaderDiffTotal >= midHeader) {
ObjectAnimator anim = ObjectAnimator.ofFloat(mHeader, "translationY", mHeader.getTranslationY(), mMinHeaderTranslation);
anim.setDuration(100);
anim.start();
mHeaderDiffTotal = mMinHeaderTranslation;
}
if (-mFooterDiffTotal > 0 && -mFooterDiffTotal < midFooter) {
// slide up
ObjectAnimator anim = ObjectAnimator.ofFloat(mFooter, "translationY", mFooter.getTranslationY(), 0);
anim.setDuration(100);
anim.start();
mFooterDiffTotal = 0;
} else if (-mFooterDiffTotal < mMinFooterTranslation && -mFooterDiffTotal >= midFooter) {
// slide down
ObjectAnimator anim = ObjectAnimator.ofFloat(mFooter, "translationY", mFooter.getTranslationY(), mMinFooterTranslation);
anim.setDuration(100);
anim.start();
mFooterDiffTotal = -mMinFooterTranslation;
}
break;
}
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project Android-ObservableScrollView by ksoichiro.
the class ObservableRecyclerView method onScrollChanged.
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (hasNoCallbacks()) {
return;
}
if (getChildCount() > 0) {
int firstVisiblePosition = getChildAdapterPosition(getChildAt(0));
int lastVisiblePosition = getChildAdapterPosition(getChildAt(getChildCount() - 1));
for (int i = firstVisiblePosition, j = 0; i <= lastVisiblePosition; i++, j++) {
int childHeight = 0;
View child = getChildAt(j);
if (child != null) {
if (mChildrenHeights.indexOfKey(i) < 0 || (child.getHeight() != mChildrenHeights.get(i))) {
childHeight = child.getHeight();
}
}
mChildrenHeights.put(i, childHeight);
}
View firstVisibleChild = getChildAt(0);
if (firstVisibleChild != null) {
if (mPrevFirstVisiblePosition < firstVisiblePosition) {
// scroll down
int skippedChildrenHeight = 0;
if (firstVisiblePosition - mPrevFirstVisiblePosition != 1) {
for (int i = firstVisiblePosition - 1; i > mPrevFirstVisiblePosition; i--) {
if (0 < mChildrenHeights.indexOfKey(i)) {
skippedChildrenHeight += mChildrenHeights.get(i);
} else {
// Approximate each item's height to the first visible child.
// It may be incorrect, but without this, scrollY will be broken
// when scrolling from the bottom.
skippedChildrenHeight += firstVisibleChild.getHeight();
}
}
}
mPrevScrolledChildrenHeight += mPrevFirstVisibleChildHeight + skippedChildrenHeight;
mPrevFirstVisibleChildHeight = firstVisibleChild.getHeight();
} else if (firstVisiblePosition < mPrevFirstVisiblePosition) {
// scroll up
int skippedChildrenHeight = 0;
if (mPrevFirstVisiblePosition - firstVisiblePosition != 1) {
for (int i = mPrevFirstVisiblePosition - 1; i > firstVisiblePosition; i--) {
if (0 < mChildrenHeights.indexOfKey(i)) {
skippedChildrenHeight += mChildrenHeights.get(i);
} else {
// Approximate each item's height to the first visible child.
// It may be incorrect, but without this, scrollY will be broken
// when scrolling from the bottom.
skippedChildrenHeight += firstVisibleChild.getHeight();
}
}
}
mPrevScrolledChildrenHeight -= firstVisibleChild.getHeight() + skippedChildrenHeight;
mPrevFirstVisibleChildHeight = firstVisibleChild.getHeight();
} else if (firstVisiblePosition == 0) {
mPrevFirstVisibleChildHeight = firstVisibleChild.getHeight();
mPrevScrolledChildrenHeight = 0;
}
if (mPrevFirstVisibleChildHeight < 0) {
mPrevFirstVisibleChildHeight = 0;
}
mScrollY = mPrevScrolledChildrenHeight - firstVisibleChild.getTop() + getPaddingTop();
mPrevFirstVisiblePosition = firstVisiblePosition;
dispatchOnScrollChanged(mScrollY, mFirstScroll, mDragging);
if (mFirstScroll) {
mFirstScroll = false;
}
if (mPrevScrollY < mScrollY) {
// down
mScrollState = ScrollState.UP;
} else if (mScrollY < mPrevScrollY) {
// up
mScrollState = ScrollState.DOWN;
} else {
mScrollState = ScrollState.STOP;
}
mPrevScrollY = mScrollY;
}
}
}
Aggregations