use of androidx.recyclerview.widget.RecyclerView in project UltimateRecyclerView by cymcsg.
the class ItemTouchListenerAdapter method onSingleTapUp.
@Override
public boolean onSingleTapUp(MotionEvent e) {
View view = getChildViewUnder(e);
if (view == null)
return false;
view.setPressed(false);
int position = shiftAdjustInt(recyclerView.getChildAdapterPosition(view));
if (position != AdmobAdapter.POSITION_ON_AD) {
listener.onItemClick(recyclerView, view, position);
}
return true;
}
use of androidx.recyclerview.widget.RecyclerView in project UltimateRecyclerView by cymcsg.
the class UltimateRecyclerView method enableShoworHideToolbarAndFloatingButton.
protected void enableShoworHideToolbarAndFloatingButton(RecyclerView recyclerView) {
if (mCallbacks != null) {
if (getChildCount() > 0) {
int firstVisiblePosition = recyclerView.getChildAdapterPosition(recyclerView.getChildAt(0));
int lastVisiblePosition = recyclerView.getChildAdapterPosition(recyclerView.getChildAt(recyclerView.getChildCount() - 1));
try {
for (int i = firstVisiblePosition, j = 0; i <= lastVisiblePosition; i++, j++) {
int childHeight = 0;
View child = recyclerView.getChildAt(j);
if (mChildrenHeights.indexOfKey(i) < 0 || (child != null && child.getHeight() != mChildrenHeights.get(i))) {
if (child != null)
childHeight = child.getHeight();
}
mChildrenHeights.put(i, childHeight);
}
} catch (NullPointerException e) {
e.printStackTrace();
// todo: need to solve this issue when the first child is missing from the scroll. Please also see the debug from the RV error.
// todo: 07-01 11:50:36.359 32348-32348/com.marshalchen.ultimaterecyclerview.demo D/RVerror? Attempt to invoke virtual method 'int android.view.View.getHeight()' on a null object reference
URLogs.e(e, "");
}
View firstVisibleChild = recyclerView.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();
mPrevFirstVisiblePosition = firstVisiblePosition;
mCallbacks.onScrollChanged(mScrollY, mFirstScroll, mDragging);
if (mPrevScrollY < mScrollY) {
// down
if (mFirstScroll) {
// first scroll down , mPrevScrollY == 0, reach here.
mFirstScroll = false;
mObservableScrollState = ObservableScrollState.STOP;
}
mObservableScrollState = ObservableScrollState.UP;
} else if (mScrollY < mPrevScrollY) {
// up
mObservableScrollState = ObservableScrollState.DOWN;
} else {
mObservableScrollState = ObservableScrollState.STOP;
}
if (mFirstScroll) {
mFirstScroll = false;
}
mPrevScrollY = mScrollY;
}
}
}
}
use of androidx.recyclerview.widget.RecyclerView in project UltimateRecyclerView by cymcsg.
the class UltimateRecyclerView method initViews.
protected void initViews() {
inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.ultimate_recycler_view_layout, this);
mRecyclerView = (RecyclerView) view.findViewById(R.id.ultimate_list);
mSwipeRefreshLayout = (VerticalSwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
setScrollbars();
mSwipeRefreshLayout.setEnabled(false);
if (mRecyclerView != null) {
mRecyclerView.setClipToPadding(mClipToPadding);
if (mPadding != -1.1f) {
mRecyclerView.setPadding(mPadding, mPadding, mPadding, mPadding);
} else {
mRecyclerView.setPadding(mPaddingLeft, mPaddingTop, mPaddingRight, mPaddingBottom);
}
}
defaultFloatingActionButton = (FloatingActionButton) view.findViewById(R.id.defaultFloatingActionButton);
setDefaultScrollListener();
/**
* empty view setup
*/
mEmpty = (ViewStub) view.findViewById(R.id.emptyview);
if (mEmptyId != 0) {
mEmpty.setLayoutResource(mEmptyId);
mEmptyView = mEmpty.inflate();
mEmpty.setVisibility(View.GONE);
}
/**
* floating button setup
*/
mFloatingButtonViewStub = (ViewStub) view.findViewById(R.id.floatingActionViewStub);
mFloatingButtonViewStub.setLayoutResource(mFloatingButtonId);
}
use of androidx.recyclerview.widget.RecyclerView in project UltimateRecyclerView by cymcsg.
the class UltimateRecyclerView method setScrollbars.
/**
* Add ScrollBar of Recyclerview
*/
protected void setScrollbars() {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
switch(mScrollbarsStyle) {
case SCROLLBARS_VERTICAL:
mSwipeRefreshLayout.removeView(mRecyclerView);
View verticalView = inflater.inflate(R.layout.vertical_recycler_view, mSwipeRefreshLayout, true);
mRecyclerView = (RecyclerView) verticalView.findViewById(R.id.ultimate_list);
break;
case SCROLLBARS_HORIZONTAL:
mSwipeRefreshLayout.removeView(mRecyclerView);
View horizontalView = inflater.inflate(R.layout.horizontal_recycler_view, mSwipeRefreshLayout, true);
mRecyclerView = (RecyclerView) horizontalView.findViewById(R.id.ultimate_list);
break;
default:
break;
}
}
use of androidx.recyclerview.widget.RecyclerView in project LshUtils by SenhLinsh.
the class TextBottomDecoration method onDrawOver.
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
super.onDrawOver(c, parent, state);
int itemCount = parent.getAdapter().getItemCount();
int childCount = parent.getChildCount();
if (itemCount > childCount) {
View view = parent.getChildAt(parent.getChildCount() - 1);
int position = parent.getChildAdapterPosition(view);
if (position == itemCount - 1) {
c.save();
// 计算 Footer 所占矩形范围
parent.getDecoratedBoundsWithMargins(view, mBounds);
int bottom = mBounds.bottom + Math.round(view.getTranslationY());
int top = bottom - mCurHeight;
int left = parent.getPaddingLeft();
int right = parent.getWidth() - parent.getPaddingRight();
// 裁切范围
c.clipRect(left, top, right, bottom);
// 绘制背景
if (mBgColor != 0)
c.drawColor(mBgColor);
// 绘制文字
if (mTextLayout != null) {
c.translate(0, (bottom + top) / 2f - mTextLayout.getHeight() / 2f);
mTextLayout.draw(c);
} else {
drawText(c, bottom, top, left, right);
}
c.restore();
}
}
}
Aggregations