use of android.support.v7.widget.RecyclerView in project Android-Iconics by mikepenz.
the class IconsFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Init and Setup RecyclerView
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
//animator not yet working
recyclerView.setItemAnimator(new DefaultItemAnimator());
mAdapter = new FastItemAdapter<>();
configAdapter();
recyclerView.setAdapter(mAdapter);
if (getArguments() != null) {
String fontName = getArguments().getString(FONT_NAME);
for (ITypeface iTypeface : Iconics.getRegisteredFonts(getActivity())) {
if (iTypeface.getFontName().equalsIgnoreCase(fontName)) {
if (iTypeface.getIcons() != null) {
for (String icon : iTypeface.getIcons()) {
icons.add(new IconItem(icon));
}
mAdapter.set(icons);
break;
}
}
}
}
//filter if a search param was provided
onSearch(search);
}
use of android.support.v7.widget.RecyclerView in project MaterialDrawer by mikepenz.
the class DrawerBuilder method createContent.
/**
* the helper method to create the content for the drawer
*/
private void createContent() {
//if we have a customView use this
if (mCustomView != null) {
LinearLayout.LayoutParams contentParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
contentParams.weight = 1f;
mSliderLayout.addView(mCustomView, contentParams);
return;
}
//set the shadow for the drawer
if (Build.VERSION.SDK_INT < 21 && mDrawerLayout != null) {
if (ViewCompat.getLayoutDirection(mRootView) == ViewCompat.LAYOUT_DIRECTION_LTR) {
mDrawerLayout.setDrawerShadow(mDrawerGravity == GravityCompat.START ? R.drawable.material_drawer_shadow_right : R.drawable.material_drawer_shadow_left, mDrawerGravity);
} else {
mDrawerLayout.setDrawerShadow(mDrawerGravity == GravityCompat.START ? R.drawable.material_drawer_shadow_left : R.drawable.material_drawer_shadow_right, mDrawerGravity);
}
}
// if we have an adapter (either by defining a custom one or the included one add a list :D
View contentView;
if (mRecyclerView == null) {
contentView = LayoutInflater.from(mActivity).inflate(R.layout.material_drawer_recycler_view, mSliderLayout, false);
mRecyclerView = (RecyclerView) contentView.findViewById(R.id.material_drawer_recycler_view);
//set the itemAnimator
mRecyclerView.setItemAnimator(mItemAnimator);
//some style improvements on older devices
mRecyclerView.setFadingEdgeLength(0);
//set the drawing cache background to the same color as the slider to improve performance
//mRecyclerView.setDrawingCacheBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mActivity, R.attr.material_drawer_background, R.color.material_drawer_background));
mRecyclerView.setClipToPadding(false);
//additional stuff
mRecyclerView.setLayoutManager(mLayoutManager);
int paddingTop = 0;
if ((mDisplayBelowStatusBar == null || mDisplayBelowStatusBar) && !mSystemUIHidden) {
paddingTop = UIUtils.getStatusBarHeight(mActivity);
}
int paddingBottom = 0;
int orientation = mActivity.getResources().getConfiguration().orientation;
if (((mTranslucentNavigationBar || mFullscreen) && Build.VERSION.SDK_INT >= 21) && !mSystemUIHidden && (orientation == Configuration.ORIENTATION_PORTRAIT || (orientation == Configuration.ORIENTATION_LANDSCAPE && DrawerUIUtils.isSystemBarOnBottom(mActivity)))) {
paddingBottom = UIUtils.getNavigationBarHeight(mActivity);
}
mRecyclerView.setPadding(0, paddingTop, 0, paddingBottom);
} else {
contentView = mRecyclerView;
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.weight = 1f;
mSliderLayout.addView(contentView, params);
if (mInnerShadow) {
View innerShadow = mSliderLayout.findViewById(R.id.material_drawer_inner_shadow);
innerShadow.setVisibility(View.VISIBLE);
innerShadow.bringToFront();
if (mDrawerGravity == GravityCompat.START) {
innerShadow.setBackgroundResource(R.drawable.material_drawer_shadow_left);
} else {
innerShadow.setBackgroundResource(R.drawable.material_drawer_shadow_right);
}
}
// set the background
if (mSliderBackgroundColor != 0) {
mSliderLayout.setBackgroundColor(mSliderBackgroundColor);
} else if (mSliderBackgroundColorRes != -1) {
mSliderLayout.setBackgroundColor(ContextCompat.getColor(mActivity, mSliderBackgroundColorRes));
} else if (mSliderBackgroundDrawable != null) {
UIUtils.setBackground(mSliderLayout, mSliderBackgroundDrawable);
} else if (mSliderBackgroundDrawableRes != -1) {
UIUtils.setBackground(mSliderLayout, mSliderBackgroundDrawableRes);
}
//handle the header
DrawerUtils.handleHeaderView(this);
//handle the footer
DrawerUtils.handleFooterView(this, new View.OnClickListener() {
@Override
public void onClick(View v) {
IDrawerItem drawerItem = (IDrawerItem) v.getTag();
DrawerUtils.onFooterDrawerItemClick(DrawerBuilder.this, drawerItem, v, true);
}
});
//if MultiSelect is possible
mAdapter.withMultiSelect(mMultiSelect);
if (mMultiSelect) {
mAdapter.withSelectOnLongClick(false);
mAdapter.withAllowDeselection(true);
}
//set the adapter on the listView
if (mAdapterWrapper == null) {
mRecyclerView.setAdapter(mAdapter);
} else {
mRecyclerView.setAdapter(mAdapterWrapper);
}
//predefine selection (should be the first element
if (mSelectedItemPosition == 0 && mSelectedItemIdentifier != 0L) {
mSelectedItemPosition = DrawerUtils.getPositionByIdentifier(this, mSelectedItemIdentifier);
}
if (mHeaderView != null && mSelectedItemPosition == 0) {
mSelectedItemPosition = 1;
}
mAdapter.deselect();
mAdapter.select(mSelectedItemPosition);
// add the onDrawerItemClickListener if set
mAdapter.withOnClickListener(new FastAdapter.OnClickListener<IDrawerItem>() {
@Override
public boolean onClick(final View view, IAdapter<IDrawerItem> adapter, final IDrawerItem item, final int position) {
if (!(item != null && item instanceof Selectable && !item.isSelectable())) {
resetStickyFooterSelection();
mCurrentStickyFooterSelection = -1;
}
//call the listener
boolean consumed = false;
//call the item specific listener
if (item instanceof AbstractDrawerItem && ((AbstractDrawerItem) item).getOnDrawerItemClickListener() != null) {
consumed = ((AbstractDrawerItem) item).getOnDrawerItemClickListener().onItemClick(view, position, item);
}
//call the drawer listener
if (mOnDrawerItemClickListener != null) {
if (mDelayDrawerClickEvent > 0) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mOnDrawerItemClickListener.onItemClick(view, position, item);
}
}, mDelayDrawerClickEvent);
} else {
consumed = mOnDrawerItemClickListener.onItemClick(view, position, item);
}
}
//we have to notify the miniDrawer if existing, and if the event was not consumed yet
if (!consumed && mMiniDrawer != null) {
consumed = mMiniDrawer.onItemClick(item);
}
//if we were a expandable item we consume the event closing makes no sense
if (item instanceof IExpandable && ((IExpandable) item).getSubItems() != null) {
//we consume the event and want no further handling
return true;
}
if (!consumed) {
//close the drawer after click
closeDrawerDelayed();
}
return consumed;
}
});
// add the onDrawerItemLongClickListener if set
mAdapter.withOnLongClickListener(new FastAdapter.OnLongClickListener<IDrawerItem>() {
@Override
public boolean onLongClick(View view, IAdapter<IDrawerItem> adapter, final IDrawerItem item, final int position) {
if (mOnDrawerItemLongClickListener != null) {
return mOnDrawerItemLongClickListener.onItemLongClick(view, position, getDrawerItem(position));
}
return false;
}
});
if (mRecyclerView != null) {
mRecyclerView.scrollToPosition(0);
}
// try to restore all saved values again
if (mSavedInstance != null) {
if (!mAppended) {
mAdapter.withSavedInstanceState(mSavedInstance, Drawer.BUNDLE_SELECTION);
DrawerUtils.setStickyFooterSelection(this, mSavedInstance.getInt(Drawer.BUNDLE_STICKY_FOOTER_SELECTION, -1), null);
} else {
mAdapter.withSavedInstanceState(mSavedInstance, Drawer.BUNDLE_SELECTION_APPENDED);
DrawerUtils.setStickyFooterSelection(this, mSavedInstance.getInt(Drawer.BUNDLE_STICKY_FOOTER_SELECTION_APPENDED, -1), null);
}
}
// call initial onClick event to allow the dev to init the first view
if (mFireInitialOnClick && mOnDrawerItemClickListener != null) {
int selection = mAdapter.getSelections().size() == 0 ? -1 : mAdapter.getSelections().iterator().next();
mOnDrawerItemClickListener.onItemClick(null, selection, getDrawerItem(selection));
}
}
use of android.support.v7.widget.RecyclerView in project MaterialDrawer by mikepenz.
the class MiniDrawer method build.
/**
* build the MiniDrawer
*
* @param ctx
* @return
*/
public View build(Context ctx) {
mContainer = new LinearLayout(ctx);
if (mInnerShadow) {
if (!mInRTL) {
mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_left);
} else {
mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_right);
}
}
//create and append recyclerView
mRecyclerView = new RecyclerView(ctx);
mContainer.addView(mRecyclerView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//set the itemAnimator
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
//some style improvements on older devices
mRecyclerView.setFadingEdgeLength(0);
//set the drawing cache background to the same color as the slider to improve performance
//mRecyclerView.setDrawingCacheBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mActivity, R.attr.material_drawer_background, R.color.material_drawer_background));
mRecyclerView.setClipToPadding(false);
//additional stuff
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
//adapter
mAdapter = new FastAdapter<>();
mItemAdapter = new ItemAdapter<>();
mAdapter.withSelectable(true);
mAdapter.withAllowDeselection(false);
mAdapter.withPositionBasedStateManagement(mPositionBasedStateManagement);
mRecyclerView.setAdapter(mItemAdapter.wrap(mAdapter));
//if the activity with the drawer should be fullscreen add the padding for the statusbar
if (mDrawer != null && mDrawer.mDrawerBuilder != null && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentStatusBar)) {
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), UIUtils.getStatusBarHeight(ctx), mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom());
}
//if the activity with the drawer should be fullscreen add the padding for the navigationBar
if (mDrawer != null && mDrawer.mDrawerBuilder != null && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentNavigationBar) && ctx.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(), mRecyclerView.getPaddingRight(), UIUtils.getNavigationBarHeight(ctx));
}
//set the adapter with the items
createItems();
return mContainer;
}
use of android.support.v7.widget.RecyclerView in project android-parallax-recyclerview by kanytu.
the class HeaderLayoutManagerFixed method smoothScrollToPosition.
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return HeaderLayoutManagerFixed.this.computeScrollVectorForPosition(targetPosition);
}
};
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
use of android.support.v7.widget.RecyclerView in project android-oss by kickstarter.
the class ActivityFeedActivity method onCreate.
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((KSApplication) getApplication()).component().inject(this);
setContentView(R.layout.activity_feed_layout);
ButterKnife.bind(this);
adapter = new ActivityFeedAdapter(viewModel.inputs);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerViewPaginator = new RecyclerViewPaginator(recyclerView, viewModel.inputs::nextPage);
swipeRefresher = new SwipeRefresher(this, swipeRefreshLayout, viewModel.inputs::refresh, viewModel.outputs::isFetchingActivities);
// Only allow refreshing if there's a current user
currentUser.observable().map(ObjectUtils::isNotNull).compose(bindToLifecycle()).compose(observeForUI()).subscribe(swipeRefreshLayout::setEnabled);
viewModel.outputs.activities().compose(bindToLifecycle()).compose(observeForUI()).subscribe(this::showActivities);
viewModel.outputs.loggedOutEmptyStateIsVisible().compose(bindToLifecycle()).compose(observeForUI()).subscribe(adapter::showLoggedOutEmptyState);
viewModel.outputs.loggedInEmptyStateIsVisible().compose(bindToLifecycle()).compose(observeForUI()).subscribe(adapter::showLoggedInEmptyState);
viewModel.outputs.goToDiscovery().compose(bindToLifecycle()).compose(observeForUI()).subscribe(__ -> resumeDiscoveryActivity());
viewModel.outputs.goToLogin().compose(bindToLifecycle()).compose(observeForUI()).subscribe(__ -> startActivityFeedLogin());
viewModel.outputs.goToProject().compose(bindToLifecycle()).compose(observeForUI()).subscribe(this::startProjectActivity);
viewModel.outputs.goToProjectUpdate().compose(bindToLifecycle()).compose(observeForUI()).subscribe(this::startProjectUpdateActivity);
}
Aggregations