use of android.support.v7.widget.RecyclerView.Recycler 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();
}
use of android.support.v7.widget.RecyclerView.Recycler in project ChipsLayoutManager by BelooS.
the class DisappearingViewsManager method getDisappearingViews.
/** @return views which moved from screen, but not deleted*/
@Override
public DisappearingViewsContainer getDisappearingViews(RecyclerView.Recycler recycler) {
final List<RecyclerView.ViewHolder> scrapList = recycler.getScrapList();
DisappearingViewsContainer container = new DisappearingViewsContainer();
for (RecyclerView.ViewHolder holder : scrapList) {
final View child = holder.itemView;
final RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
if (!lp.isItemRemoved()) {
if (lp.getViewAdapterPosition() < canvas.getMinPositionOnScreen()) {
container.backwardViews.put(lp.getViewAdapterPosition(), child);
} else if (lp.getViewAdapterPosition() > canvas.getMaxPositionOnScreen()) {
container.forwardViews.put(lp.getViewAdapterPosition(), child);
}
}
}
return container;
}
use of android.support.v7.widget.RecyclerView.Recycler in project MagicaSakura by Bilibili.
the class ThemeUtils method refreshView.
private static void refreshView(View view, ExtraRefreshable extraRefreshable) {
if (view == null)
return;
view.destroyDrawingCache();
if (view instanceof Tintable) {
((Tintable) view).tint();
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
refreshView(((ViewGroup) view).getChildAt(i), extraRefreshable);
}
}
} else {
if (extraRefreshable != null) {
extraRefreshable.refreshSpecificView(view);
}
if (view instanceof AbsListView) {
try {
if (sRecyclerBin == null) {
sRecyclerBin = AbsListView.class.getDeclaredField("mRecycler");
sRecyclerBin.setAccessible(true);
}
if (sListViewClearMethod == null) {
sListViewClearMethod = Class.forName("android.widget.AbsListView$RecycleBin").getDeclaredMethod("clear");
sListViewClearMethod.setAccessible(true);
}
sListViewClearMethod.invoke(sRecyclerBin.get(view));
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
ListAdapter adapter = ((AbsListView) view).getAdapter();
while (adapter instanceof WrapperListAdapter) {
adapter = ((WrapperListAdapter) adapter).getWrappedAdapter();
}
if (adapter instanceof BaseAdapter) {
((BaseAdapter) adapter).notifyDataSetChanged();
}
}
if (view instanceof RecyclerView) {
try {
if (sRecycler == null) {
sRecycler = RecyclerView.class.getDeclaredField("mRecycler");
sRecycler.setAccessible(true);
}
if (sRecycleViewClearMethod == null) {
sRecycleViewClearMethod = Class.forName("android.support.v7.widget.RecyclerView$Recycler").getDeclaredMethod("clear");
sRecycleViewClearMethod.setAccessible(true);
}
sRecycleViewClearMethod.invoke(sRecycler.get(view));
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
((RecyclerView) view).getRecycledViewPool().clear();
((RecyclerView) view).invalidateItemDecorations();
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
refreshView(((ViewGroup) view).getChildAt(i), extraRefreshable);
}
}
}
}
use of android.support.v7.widget.RecyclerView.Recycler in project LeafPic by HoraApps.
the class MainActivity method initUI.
private void initUI() {
/**** TOOLBAR ****/
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
/**** RECYCLER VIEW ****/
rvAlbums = (RecyclerView) findViewById(R.id.grid_albums);
rvMedia = ((RecyclerView) findViewById(R.id.grid_photos));
rvAlbums.setHasFixedSize(true);
rvAlbums.setItemAnimator(new DefaultItemAnimator());
rvMedia.setHasFixedSize(true);
rvMedia.setItemAnimator(new DefaultItemAnimator());
albumsAdapter = new AlbumsAdapter(getAlbums().dispAlbums, MainActivity.this);
albumsAdapter.setOnClickListener(albumOnClickListener);
albumsAdapter.setOnLongClickListener(albumOnLongCLickListener);
rvAlbums.setAdapter(albumsAdapter);
mediaAdapter = new MediaAdapter(getAlbum().getMedia(), MainActivity.this);
mediaAdapter.setOnClickListener(photosOnClickListener);
mediaAdapter.setOnLongClickListener(photosOnLongClickListener);
rvMedia.setAdapter(mediaAdapter);
int spanCount = SP.getInt("n_columns_folders", 2);
rvAlbumsDecoration = new GridSpacingItemDecoration(spanCount, Measure.pxToDp(3, getApplicationContext()), true);
rvAlbums.addItemDecoration(rvAlbumsDecoration);
rvAlbums.setLayoutManager(new GridLayoutManager(this, spanCount));
spanCount = SP.getInt("n_columns_media", 3);
rvMediaDecoration = new GridSpacingItemDecoration(spanCount, Measure.pxToDp(3, getApplicationContext()), true);
rvMedia.setLayoutManager(new GridLayoutManager(getApplicationContext(), spanCount));
rvMedia.addItemDecoration(rvMediaDecoration);
/**** SWIPE TO REFRESH ****/
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setColorSchemeColors(getAccentColor());
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(getBackgroundColor());
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if (albumsMode) {
getAlbums().clearSelectedAlbums();
new PrepareAlbumTask().execute();
} else {
getAlbum().clearSelectedPhotos();
new PreparePhotosTask().execute();
}
}
});
/**** DRAWER ****/
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.addDrawerListener(new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {
public void onDrawerClosed(View view) {
//Put your code here
// materialMenu.animateIconState(MaterialMenuDrawable.IconState.BURGER);
}
public void onDrawerOpened(View drawerView) {
//Put your code here
//materialMenu.animateIconState(MaterialMenuDrawable.IconState.ARROW);
}
});
/**** FAB ***/
fabCamera = (FloatingActionButton) findViewById(R.id.fab_camera);
fabCamera.setImageDrawable(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_camera_alt).color(Color.WHITE));
fabCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA));
}
});
//region TESTING
fabCamera.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// NOTE: this is used to acquire write permission on sd with api 21
// TODO call this one when unable to write on sd
requestSdCardPermissions();
return false;
}
});
//endregion
setRecentApp(getString(R.string.app_name));
setupUI();
}
use of android.support.v7.widget.RecyclerView.Recycler in project greedo-layout-for-android by 500px.
the class GreedoLayoutManager method preFillGrid.
/**
* Find first visible position, scrap all children, and then layout all visible views returning
* the number of pixels laid out, which could be greater than the entire view (useful for scroll
* functions).
* @param direction The direction we are filling the grid in
* @param dy Vertical offset, creating a gap that we need to fill
* @param emptyTop Offset we begin filling at
* @return Number of vertical pixels laid out
*/
private int preFillGrid(Direction direction, int dy, int emptyTop, RecyclerView.Recycler recycler, RecyclerView.State state) {
int newFirstVisiblePosition = firstChildPositionForRow(mFirstVisibleRow);
// First, detach all existing views from the layout. detachView() is a lightweight operation
// that we can use to quickly reorder views without a full add/remove.
SparseArray<View> viewCache = new SparseArray<>(getChildCount());
int startLeftOffset = getPaddingLeft();
int startTopOffset = getPaddingTop() + emptyTop;
if (getChildCount() != 0) {
startTopOffset = getDecoratedTop(getChildAt(0));
if (mFirstVisiblePosition != newFirstVisiblePosition) {
switch(direction) {
case // new row above may be shown
UP:
double previousTopRowHeight = sizeForChildAtPosition(mFirstVisiblePosition - 1).getHeight();
startTopOffset -= previousTopRowHeight;
break;
case // row may have gone off screen
DOWN:
double topRowHeight = sizeForChildAtPosition(mFirstVisiblePosition).getHeight();
startTopOffset += topRowHeight;
break;
}
}
// Cache all views by their existing position, before updating counts
for (int i = 0; i < getChildCount(); i++) {
int position = mFirstVisiblePosition + i;
final View child = getChildAt(i);
viewCache.put(position, child);
}
// Temporarily detach all cached views. Views we still need will be added back at the proper index
for (int i = 0; i < viewCache.size(); i++) {
final View cachedView = viewCache.valueAt(i);
detachView(cachedView);
}
}
mFirstVisiblePosition = newFirstVisiblePosition;
// Next, supply the grid of items that are deemed visible. If they were previously there,
// they will simply be re-attached. New views that must be created are obtained from
// the Recycler and added.
int leftOffset = startLeftOffset;
int topOffset = startTopOffset + mPendingScrollPositionOffset;
int nextPosition = mFirstVisiblePosition;
while (nextPosition >= 0 && nextPosition < state.getItemCount()) {
boolean isViewCached = true;
View view = viewCache.get(nextPosition);
if (view == null) {
view = recycler.getViewForPosition(nextPosition);
isViewCached = false;
}
if (mIsFirstViewHeader && nextPosition == HEADER_POSITION) {
measureChildWithMargins(view, 0, 0);
mHeaderViewSize = new Size(view.getMeasuredWidth(), view.getMeasuredHeight());
}
// Overflow to next row if we don't fit
Size viewSize = sizeForChildAtPosition(nextPosition);
if ((leftOffset + viewSize.getWidth()) > getContentWidth()) {
leftOffset = startLeftOffset;
Size previousViewSize = sizeForChildAtPosition(nextPosition - 1);
topOffset += previousViewSize.getHeight();
}
// These next children would no longer be visible, stop here
boolean isAtEndOfContent;
switch(direction) {
case DOWN:
isAtEndOfContent = topOffset >= getContentHeight() + dy;
break;
default:
isAtEndOfContent = topOffset >= getContentHeight();
break;
}
if (isAtEndOfContent)
break;
if (isViewCached) {
// Re-attach the cached view at its new index
attachView(view);
viewCache.remove(nextPosition);
} else {
addView(view);
measureChildWithMargins(view, 0, 0);
int right = leftOffset + viewSize.getWidth();
int bottom = topOffset + viewSize.getHeight();
layoutDecorated(view, leftOffset, topOffset, right, bottom);
}
leftOffset += viewSize.getWidth();
nextPosition++;
}
// Scrap and store views that were not re-attached (no longer visible).
for (int i = 0; i < viewCache.size(); i++) {
final View removingView = viewCache.valueAt(i);
recycler.recycleView(removingView);
}
// Calculate pixels laid out during fill
int pixelsFilled = 0;
if (getChildCount() > 0) {
pixelsFilled = getChildAt(getChildCount() - 1).getBottom();
}
return pixelsFilled;
}
Aggregations