use of android.support.v7.widget.RecyclerView.Recycler in project Carbon by ZieIony.
the class ScrollFlagsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrollflags);
RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
recycler.setLayoutManager(new LinearLayoutManager(this));
/*RowListAdapter<AvatarTextListItemActivity.SampleItem> adapter = new RowListAdapter<>(AvatarTextListItemActivity.SampleItem.class, AvatarTextRow::new);
recycler.setAdapter(adapter);
adapter.setItems(Stream.generate(AvatarTextListItemActivity.SampleItem::new).limit(10).collect(Collectors.toList()));
*/
}
use of android.support.v7.widget.RecyclerView.Recycler in project SeriesGuide by UweTrottmann.
the class MoviesNowFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_now, container, false);
unbinder = ButterKnife.bind(this, v);
swipeRefreshLayout.setSwipeableChildren(R.id.scrollViewNow, R.id.recyclerViewNow);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshStream();
}
});
swipeRefreshLayout.setProgressViewOffset(false, getResources().getDimensionPixelSize(R.dimen.swipe_refresh_progress_bar_start_margin), getResources().getDimensionPixelSize(R.dimen.swipe_refresh_progress_bar_end_margin));
emptyView.setText(R.string.now_movies_empty);
showError(null);
snackbarButton.setText(R.string.refresh);
snackbarButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
refreshStream();
}
});
// recycler view layout manager
final int spanCount = getResources().getInteger(R.integer.grid_column_count);
final GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), spanCount);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (adapter == null) {
return 1;
}
if (position >= adapter.getItemCount()) {
return 1;
}
// make headers and more links span all columns
int type = adapter.getItem(position).type;
return (type == NowAdapter.ItemType.HEADER || type == NowAdapter.ItemType.MORE_LINK) ? spanCount : 1;
}
});
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(new GridInsetDecoration(getResources()));
recyclerView.setHasFixedSize(true);
return v;
}
use of android.support.v7.widget.RecyclerView.Recycler in project AndroidChromium by JackyAndroid.
the class NewTabPageRecyclerView method snapScroll.
/**
* Snaps the scroll point of the RecyclerView to prevent the user from scrolling to midway
* through a transition and to allow peeking card behaviour.
*/
public void snapScroll(View fakeBox, int parentScrollY, int parentHeight) {
// Snap scroll to prevent resting in the middle of the omnibox transition.
final int searchBoxTransitionLength = getResources().getDimensionPixelSize(R.dimen.ntp_search_box_transition_length);
int fakeBoxUpperBound = fakeBox.getTop() + fakeBox.getPaddingTop();
if (scrollOutOfRegion(fakeBoxUpperBound - searchBoxTransitionLength, fakeBoxUpperBound)) {
// The snap scrolling regions should never overlap.
return;
}
// Snap scroll to prevent resting in the middle of the peeking card transition
// and to allow the peeking card to peek a bit before snapping back.
CardViewHolder peekingCardViewHolder = findFirstCard();
if (peekingCardViewHolder != null && isFirstItemVisible()) {
if (!mHasSpaceForPeekingCard)
return;
ViewHolder firstHeaderViewHolder = findFirstHeader();
// That one does not peek.
if (firstHeaderViewHolder == null)
return;
View peekingCardView = peekingCardViewHolder.itemView;
View headerView = firstHeaderViewHolder.itemView;
final int peekingHeight = getResources().getDimensionPixelSize(R.dimen.snippets_padding_and_peeking_card_height);
// |A + B - C| gives the offset of the peeking card relative to the Recycler View,
// so scrolling to this point would put the peeking card at the top of the
// screen. Remove the |headerView| height which gets dynamically increased with
// scrolling.
// |A + B - C - D| will scroll us so that the peeking card is just off the bottom
// of the screen.
// Finally, we get |A + B - C - D + E| because the transition starts from the
// peeking card's resting point, which is |E| from the bottom of the screen.
int start = // A.
peekingCardView.getTop() + // B.
parentScrollY - // C.
headerView.getHeight() - // D.
parentHeight + // E.
peekingHeight;
// The height of the region in which the the peeking card will snap.
int snapScrollHeight = peekingHeight + headerView.getHeight();
scrollOutOfRegion(start, start + snapScrollHeight, start + snapScrollHeight);
}
}
use of android.support.v7.widget.RecyclerView.Recycler in project FastAdapter by mikepenz.
the class SimpleSwipeCallback method onChildDraw.
//Inspired/modified from: https://github.com/nemanja-kovacevic/recycler-view-swipe-to-delete/blob/master/app/src/main/java/net/nemanjakovacevic/recyclerviewswipetodelete/MainActivity.java
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
View itemView = viewHolder.itemView;
if (viewHolder.getAdapterPosition() == RecyclerView.NO_POSITION) {
return;
}
if (Math.abs(dX) > Math.abs(dY)) {
boolean isLeft = dX < 0;
if (bgPaint == null) {
bgPaint = new Paint();
if (horizontalMargin == Integer.MAX_VALUE) {
withHorizontalMarginDp(recyclerView.getContext(), 16);
}
}
bgPaint.setColor(isLeft ? bgColorLeft : bgColorRight);
if (bgPaint.getColor() != Color.TRANSPARENT) {
int left = isLeft ? itemView.getRight() + (int) dX : itemView.getLeft();
int right = isLeft ? itemView.getRight() : (itemView.getLeft() + (int) dX);
c.drawRect(left, itemView.getTop(), right, itemView.getBottom(), bgPaint);
}
Drawable drawable = isLeft ? leaveBehindDrawableLeft : leaveBehindDrawableRight;
if (drawable != null) {
int itemHeight = itemView.getBottom() - itemView.getTop();
int intrinsicWidth = drawable.getIntrinsicWidth();
int intrinsicHeight = drawable.getIntrinsicWidth();
int left;
int right;
if (isLeft) {
left = itemView.getRight() - horizontalMargin - intrinsicWidth;
right = itemView.getRight() - horizontalMargin;
} else {
left = itemView.getLeft() + horizontalMargin;
right = itemView.getLeft() + horizontalMargin + intrinsicWidth;
}
int top = itemView.getTop() + (itemHeight - intrinsicHeight) / 2;
int bottom = top + intrinsicHeight;
drawable.setBounds(left, top, right, bottom);
drawable.draw(c);
}
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
use of android.support.v7.widget.RecyclerView.Recycler in project platform_frameworks_base by android.
the class DirectoryFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Context context = getActivity();
final State state = getDisplayState();
// Read arguments when object created for the first time.
// Restore state if fragment recreated.
Bundle args = savedInstanceState == null ? getArguments() : savedInstanceState;
mRoot = args.getParcelable(Shared.EXTRA_ROOT);
mDocument = args.getParcelable(Shared.EXTRA_DOC);
mStateKey = buildStateKey(mRoot, mDocument);
mQuery = args.getString(Shared.EXTRA_QUERY);
mType = args.getInt(Shared.EXTRA_TYPE);
final Selection selection = args.getParcelable(Shared.EXTRA_SELECTION);
mSelection = selection != null ? selection : new Selection();
mSearchMode = args.getBoolean(Shared.EXTRA_SEARCH_MODE);
mIconHelper = new IconHelper(context, MODE_GRID);
mAdapter = new SectionBreakDocumentsAdapterWrapper(this, new ModelBackedDocumentsAdapter(this, mIconHelper));
mRecView.setAdapter(mAdapter);
// Switch Access Accessibility API needs an {@link AccessibilityDelegate} to know the proper
// route when user selects an UI element. It usually guesses this if the element has an
// {@link OnClickListener}, but since we do not have one for itemView, we will need to
// manually route it to the right behavior. RecyclerView has its own AccessibilityDelegate,
// and routes it to its LayoutManager; so we must override the LayoutManager's accessibility
// methods to route clicks correctly.
mLayout = new GridLayoutManager(getContext(), mColumnCount) {
@Override
public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfoForItem(recycler, state, host, info);
info.addAction(AccessibilityActionCompat.ACTION_CLICK);
}
@Override
public boolean performAccessibilityActionForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View view, int action, Bundle args) {
// We are only handling click events; route all other to default implementation
if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) {
RecyclerView.ViewHolder vh = mRecView.getChildViewHolder(view);
if (vh instanceof DocumentHolder) {
DocumentHolder dh = (DocumentHolder) vh;
if (dh.mEventListener != null) {
dh.mEventListener.onActivate(dh);
return true;
}
}
}
return super.performAccessibilityActionForItem(recycler, state, view, action, args);
}
};
SpanSizeLookup lookup = mAdapter.createSpanSizeLookup();
if (lookup != null) {
mLayout.setSpanSizeLookup(lookup);
}
mRecView.setLayoutManager(mLayout);
mGestureDetector = new ListeningGestureDetector(this.getContext(), mDragHelper, new GestureListener());
mRecView.addOnItemTouchListener(mGestureDetector);
// TODO: instead of inserting the view into the constructor, extract listener-creation code
// and set the listener on the view after the fact. Then the view doesn't need to be passed
// into the selection manager.
mSelectionManager = new MultiSelectManager(mRecView, mAdapter, state.allowMultiple ? MultiSelectManager.MODE_MULTIPLE : MultiSelectManager.MODE_SINGLE, null);
mSelectionManager.addCallback(new SelectionModeListener());
mModel = new Model();
mModel.addUpdateListener(mAdapter);
mModel.addUpdateListener(mModelUpdateListener);
// Make sure this is done after the RecyclerView is set up.
mFocusManager = new FocusManager(context, mRecView, mModel);
mTuner = FragmentTuner.pick(getContext(), state);
mClipper = new DocumentClipper(context);
final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
boolean svelte = am.isLowRamDevice() && (mType == TYPE_RECENT_OPEN);
mIconHelper.setThumbnailsEnabled(!svelte);
// Kick off loader at least once
getLoaderManager().restartLoader(LOADER_ID, null, this);
}
Aggregations