Search in sources :

Example 11 with MaterializeBuilder

use of com.mikepenz.materialize.MaterializeBuilder 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);
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) StickyHeaderAdapter(com.mikepenz.fastadapter.app.adapters.StickyHeaderAdapter) IItem(com.mikepenz.fastadapter.IItem) IAdapter(com.mikepenz.fastadapter.IAdapter) Toolbar(android.support.v7.widget.Toolbar) IExpandable(com.mikepenz.fastadapter.IExpandable) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) StickyRecyclerHeadersDecoration(com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration) ActionMode(android.support.v7.view.ActionMode) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) IconicsLayoutInflater(com.mikepenz.iconics.context.IconicsLayoutInflater) ActionModeHelper(com.mikepenz.fastadapter_extensions.ActionModeHelper)

Example 12 with MaterializeBuilder

use of com.mikepenz.materialize.MaterializeBuilder 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);
}
Also used : CheckBoxSampleItem(com.mikepenz.fastadapter.app.items.CheckBoxSampleItem) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Random(java.util.Random) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) Toolbar(android.support.v7.widget.Toolbar)

Example 13 with MaterializeBuilder

use of com.mikepenz.materialize.MaterializeBuilder in project FastAdapter by mikepenz.

the class RadioButtonSampleActivity 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<RadioButtonSampleItem>() {

        @Override
        public boolean onClick(View v, IAdapter<RadioButtonSampleItem> adapter, RadioButtonSampleItem 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<RadioButtonSampleItem>() {

        @Override
        public boolean onClick(View v, IAdapter<RadioButtonSampleItem> adapter, RadioButtonSampleItem item, int position) {
            // consume otherwise radio/checkbox will be deselected
            return true;
        }
    });
    fastItemAdapter.withItemEvent(new RadioButtonSampleItem.RadioButtonClickEvent());
    //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<RadioButtonSampleItem> items = new ArrayList<>();
    for (String s : ALPHABET) {
        int count = new Random().nextInt(20);
        for (int i = 1; i <= count; i++) {
            items.add(new RadioButtonSampleItem().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);
}
Also used : ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Random(java.util.Random) RadioButtonSampleItem(com.mikepenz.fastadapter.app.items.RadioButtonSampleItem) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) Toolbar(android.support.v7.widget.Toolbar)

Example 14 with MaterializeBuilder

use of com.mikepenz.materialize.MaterializeBuilder in project FastAdapter by mikepenz.

the class SortActivity 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_sort);
    ButterKnife.bind(this);
    // Handle 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<SimpleItem>() {

        @Override
        public boolean onClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, int position) {
            Toast.makeText(v.getContext(), (item).name.getText(v.getContext()), Toast.LENGTH_LONG).show();
            return false;
        }
    });
    //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);
    if (savedInstanceState != null) {
        //Retrieve the previous sorting strategy from the instance state
        sortingStrategy = toSortingStrategy(savedInstanceState.getInt("sorting_strategy"));
    } else {
        //Set the default so
        sortingStrategy = SORT_NONE;
    }
    //we sort the list
    fastItemAdapter.getItemAdapter().withComparator(getComparator());
    //initial filling of the list
    fastItemAdapter.setNewList(generateUnsortedList());
    //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);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) SimpleItem(com.mikepenz.fastadapter.app.items.SimpleItem) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 15 with MaterializeBuilder

use of com.mikepenz.materialize.MaterializeBuilder in project FastAdapter by mikepenz.

the class GenericItemActivity 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_generic_item);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter which will manage everything
    fastAdapter = new FastAdapter();
    fastAdapter.withSelectable(true);
    //get our recyclerView and do basic setup
    RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
    //init our gridLayoutManager and configure RV
    GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
    GenericItemAdapter<IconModel, GenericIconItem> itemAdapter = new GenericItemAdapter<>(GenericIconItem.class, IconModel.class);
    final FastScrollIndicatorAdapter<GenericIconItem> fastScrollIndicatorAdapter = new FastScrollIndicatorAdapter<>();
    rv.setAdapter(fastScrollIndicatorAdapter.wrap(itemAdapter.wrap(fastAdapter)));
    DragScrollBar materialScrollBar = new DragScrollBar(this, rv, true);
    materialScrollBar.setHandleColour(ContextCompat.getColor(this, R.color.colorAccent));
    materialScrollBar.setHandleOffColour(ContextCompat.getColor(this, R.color.colorAccent));
    materialScrollBar.addIndicator(new CustomIndicator(this), true);
    rv.setLayoutManager(gridLayoutManager);
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    //order fonts by their name
    List<ITypeface> mFonts = new ArrayList<>(Iconics.getRegisteredFonts(this));
    Collections.sort(mFonts, new Comparator<ITypeface>() {

        @Override
        public int compare(final ITypeface object1, final ITypeface object2) {
            return object1.getFontName().compareTo(object2.getFontName());
        }
    });
    //add all icons of all registered Fonts to the list
    ArrayList<IconModel> models = new ArrayList<>();
    for (ITypeface font : mFonts) {
        for (String icon : font.getIcons()) {
            models.add(new IconModel(font.getIcon(icon)));
        }
    }
    //fill with some sample data
    itemAdapter.addModel(models);
    //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);
}
Also used : FastScrollIndicatorAdapter(com.mikepenz.fastadapter.app.adapters.FastScrollIndicatorAdapter) IconModel(com.mikepenz.fastadapter.app.generic.IconModel) DragScrollBar(com.turingtechnologies.materialscrollbar.DragScrollBar) GenericIconItem(com.mikepenz.fastadapter.app.generic.GenericIconItem) ArrayList(java.util.ArrayList) CustomIndicator(com.turingtechnologies.materialscrollbar.CustomIndicator) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) GridLayoutManager(android.support.v7.widget.GridLayoutManager) SlideDownAlphaAnimator(com.mikepenz.itemanimators.SlideDownAlphaAnimator) GenericItemAdapter(com.mikepenz.fastadapter.adapters.GenericItemAdapter) ITypeface(com.mikepenz.iconics.typeface.ITypeface) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)16 MaterializeBuilder (com.mikepenz.materialize.MaterializeBuilder)16 Toolbar (android.support.v7.widget.Toolbar)15 FastAdapter (com.mikepenz.fastadapter.FastAdapter)14 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)13 ArrayList (java.util.ArrayList)12 View (android.view.View)11 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)9 SlideDownAlphaAnimator (com.mikepenz.itemanimators.SlideDownAlphaAnimator)6 IItem (com.mikepenz.fastadapter.IItem)5 SimpleItem (com.mikepenz.fastadapter.app.items.SimpleItem)5 GridLayoutManager (android.support.v7.widget.GridLayoutManager)4 IconicsLayoutInflater (com.mikepenz.iconics.context.IconicsLayoutInflater)4 Random (java.util.Random)4 ActionMode (android.support.v7.view.ActionMode)3 SearchView (android.support.v7.widget.SearchView)3 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)3 IItemAdapter (com.mikepenz.fastadapter.IItemAdapter)3 ActionModeHelper (com.mikepenz.fastadapter_extensions.ActionModeHelper)3 ITypeface (com.mikepenz.iconics.typeface.ITypeface)3