use of android.support.v7.widget.LinearLayoutManager in project FastAdapter by mikepenz.
the class StickyHeaderSampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.sample_sticky_header);
//style our ui
new MaterializeBuilder().withActivity(this).build();
//create our FastAdapter
fastAdapter = new FastAdapter();
fastAdapter.withSelectable(true);
//create our adapters
final StickyHeaderAdapter stickyHeaderAdapter = new StickyHeaderAdapter();
final HeaderAdapter headerAdapter = new HeaderAdapter();
final ItemAdapter itemAdapter = new ItemAdapter();
//configure our fastAdapter
//as we provide id's for the items we want the hasStableIds enabled to speed up things
fastAdapter.setHasStableIds(true);
//get our recyclerView and do basic setup
RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
rv.setLayoutManager(new LinearLayoutManager(this));
rv.setItemAnimator(new DefaultItemAnimator());
rv.setAdapter(stickyHeaderAdapter.wrap(itemAdapter.wrap(headerAdapter.wrap(fastAdapter))));
//this adds the Sticky Headers within our list
final StickyRecyclerHeadersDecoration decoration = new StickyRecyclerHeadersDecoration(stickyHeaderAdapter);
rv.addItemDecoration(decoration);
//fill with some sample data
headerAdapter.add(new SimpleItem().withName("Header").withIdentifier(1));
List<IItem> items = new ArrayList<>();
for (int i = 1; i <= 100; i++) {
items.add(new SimpleItem().withName("Test " + i).withHeader(headers[i / 5]).withIdentifier(100 + i));
}
itemAdapter.add(items);
//so the headers are aware of changes
stickyHeaderAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
decoration.invalidateHeaders();
}
});
//restore selections (this has to be done after the items were added
fastAdapter.withSavedInstanceState(savedInstanceState);
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
}
use of android.support.v7.widget.LinearLayoutManager in project FastAdapter by mikepenz.
the class AdvancedSampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
//as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater
//https://github.com/mikepenz/Android-Iconics
LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.sample_advanced);
//style our ui
new MaterializeBuilder().withActivity(this).build();
//create our FastAdapter
mFastAdapter = new FastAdapter<>();
//we init our ActionModeHelper
mActionModeHelper = new ActionModeHelper(mFastAdapter, R.menu.cab, new ActionBarCallBack());
mActionModeHelper.withSupportSubItems(true);
//create our adapters
final StickyHeaderAdapter stickyHeaderAdapter = new StickyHeaderAdapter();
mItemAdapter = new ItemAdapter<>();
mHeaderAdapter = new HeaderAdapter<>();
//configure our mFastAdapter
//as we provide id's for the items we want the hasStableIds enabled to speed up things
mFastAdapter.withSelectable(true);
mFastAdapter.withMultiSelect(true);
mFastAdapter.withSelectOnLongClick(true);
mFastAdapter.withPositionBasedStateManagement(false);
mFastAdapter.withOnPreClickListener(new FastAdapter.OnClickListener<IItem>() {
@Override
public boolean onClick(View v, IAdapter adapter, IItem item, int position) {
//we handle the default onClick behavior for the actionMode. This will return null if it didn't do anything and you can handle a normal onClick
Boolean res = mActionModeHelper.onClick(item);
return res != null ? res : false;
}
});
mFastAdapter.withOnPreLongClickListener(new FastAdapter.OnLongClickListener<IItem>() {
@Override
public boolean onLongClick(View v, IAdapter adapter, IItem item, int position) {
//we do not want expandable items to be selected
if (item instanceof IExpandable) {
if (((IExpandable) item).getSubItems() != null) {
return true;
}
}
//handle the longclick actions
ActionMode actionMode = mActionModeHelper.onLongClick(AdvancedSampleActivity.this, position);
if (actionMode != null) {
//we want color our CAB
findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(AdvancedSampleActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));
}
//if we have no actionMode we do not consume the event
return actionMode != null;
}
});
//get our recyclerView and do basic setup
RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
rv.setLayoutManager(new LinearLayoutManager(this));
rv.setItemAnimator(new DefaultItemAnimator());
rv.setAdapter(stickyHeaderAdapter.wrap(mItemAdapter.wrap(mHeaderAdapter.wrap(mFastAdapter))));
final StickyRecyclerHeadersDecoration decoration = new StickyRecyclerHeadersDecoration(stickyHeaderAdapter);
rv.addItemDecoration(decoration);
//so the headers are aware of changes
stickyHeaderAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
decoration.invalidateHeaders();
}
});
//init cache with the added items, this is useful for shorter lists with many many different view types (at least 4 or more
//new RecyclerViewCacheUtil().withCacheSize(2).apply(rv, items);
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
//we define the items
setItems();
//restore selections (this has to be done after the items were added
mFastAdapter.withSavedInstanceState(savedInstanceState);
}
use of android.support.v7.widget.LinearLayoutManager in project FastAdapter by mikepenz.
the class CheckBoxSampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//style our ui
new MaterializeBuilder().withActivity(this).build();
//create our FastAdapter which will manage everything
fastItemAdapter = new FastItemAdapter<>();
fastItemAdapter.withSelectable(true);
//configure our fastAdapter
fastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener<CheckBoxSampleItem>() {
@Override
public boolean onClick(View v, IAdapter<CheckBoxSampleItem> adapter, CheckBoxSampleItem item, int position) {
Toast.makeText(v.getContext(), (item).name.getText(v.getContext()), Toast.LENGTH_LONG).show();
return false;
}
});
//init the ClickListenerHelper which simplifies custom click listeners on views of the Adapter
mClickListenerHelper = new ClickListenerHelper<>(fastItemAdapter);
fastItemAdapter.withOnPreClickListener(new FastAdapter.OnClickListener<CheckBoxSampleItem>() {
@Override
public boolean onClick(View v, IAdapter<CheckBoxSampleItem> adapter, CheckBoxSampleItem item, int position) {
// consume otherwise radio/checkbox will be deselected
return true;
}
});
fastItemAdapter.withItemEvent(new CheckBoxSampleItem.CheckBoxClickEvent());
//get our recyclerView and do basic setup
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(fastItemAdapter);
//fill with some sample data
int x = 0;
List<CheckBoxSampleItem> items = new ArrayList<>();
for (String s : ALPHABET) {
int count = new Random().nextInt(20);
for (int i = 1; i <= count; i++) {
items.add(new CheckBoxSampleItem().withName(s + " Test " + x).withIdentifier(100 + x));
x++;
}
}
fastItemAdapter.add(items);
//restore selections (this has to be done after the items were added
fastItemAdapter.withSavedInstanceState(savedInstanceState);
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
}
use of android.support.v7.widget.LinearLayoutManager in project MaterialDrawer by mikepenz.
the class DrawerBuilder method withActivity.
/**
* Sets the activity which will be generated for the generation
* The activity is required and will be used to inflate the content in.
* After generation it is set to null to prevent a memory leak.
*
* @param activity current activity which will contain the drawer
*/
public DrawerBuilder withActivity(@NonNull Activity activity) {
this.mRootView = (ViewGroup) activity.findViewById(android.R.id.content);
this.mActivity = activity;
this.mLayoutManager = new LinearLayoutManager(mActivity);
return this;
}
use of android.support.v7.widget.LinearLayoutManager 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;
}
Aggregations