Search in sources :

Example 31 with GridLayoutManager

use of android.support.v7.widget.GridLayoutManager in project FastAdapter by mikepenz.

the class IconGridActivity 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_icon_grid);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter which will manage everything
    fastItemAdapter = new FastItemAdapter();
    //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);
    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            switch(fastItemAdapter.getItemViewType(position)) {
                case R.id.fastadapter_expandable_item_id:
                    return 3;
                case R.id.fastadapter_icon_item_id:
                    return 1;
                default:
                    return -1;
            }
        }
    });
    rv.setLayoutManager(gridLayoutManager);
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    rv.setAdapter(fastItemAdapter);
    //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
    int count = 0;
    ArrayList<SimpleSubExpandableItem> items = new ArrayList<>(Iconics.getRegisteredFonts(this).size());
    for (ITypeface font : mFonts) {
        //we set the identifier from the count here, as I need a stable ID in the sample to showcase the state restore
        SimpleSubExpandableItem expandableItem = new SimpleSubExpandableItem();
        expandableItem.withName(font.getFontName()).withIdentifier(count);
        ArrayList<IItem> icons = new ArrayList<>();
        for (String icon : font.getIcons()) {
            IconItem iconItem = new IconItem();
            iconItem.withIcon(font.getIcon(icon));
            icons.add(iconItem);
        }
        expandableItem.withSubItems(icons);
        items.add(expandableItem);
        count++;
    }
    //fill with some sample data
    fastItemAdapter.add(items);
    //if first start we want to expand the item with ID 2
    if (savedInstanceState != null) {
        //restore selections (this has to be done after the items were added
        fastItemAdapter.withSavedInstanceState(savedInstanceState);
    } else {
        //expand one item to make sample look a bit more interesting
        fastItemAdapter.expand(2);
    }
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
}
Also used : SimpleSubExpandableItem(com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem) FastItemAdapter(com.mikepenz.fastadapter.commons.adapters.FastItemAdapter) ArrayList(java.util.ArrayList) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) GridLayoutManager(android.support.v7.widget.GridLayoutManager) SlideDownAlphaAnimator(com.mikepenz.itemanimators.SlideDownAlphaAnimator) IconItem(com.mikepenz.fastadapter.app.items.IconItem) ITypeface(com.mikepenz.iconics.typeface.ITypeface) RecyclerView(android.support.v7.widget.RecyclerView) IItem(com.mikepenz.fastadapter.IItem) IconicsLayoutInflater(com.mikepenz.iconics.context.IconicsLayoutInflater) Toolbar(android.support.v7.widget.Toolbar)

Example 32 with GridLayoutManager

use of android.support.v7.widget.GridLayoutManager in project FastAdapter by mikepenz.

the class MultiTypeGenericItemActivity 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_multi_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);
    //if you need multiple items for different models you can also do this be defining a Function which get's the model object and returns the item (extends IItem)
    GenericItemAdapter<IconModel, GenericIconItem> itemAdapter = new GenericItemAdapter<>(new Function<IconModel, GenericIconItem>() {

        @Override
        public GenericIconItem apply(IconModel o) {
            if (o instanceof RightIconModel) {
                return new RightGenericIconItem(o);
            } else {
                return new GenericIconItem(o);
            }
        }
    });
    rv.setLayoutManager(gridLayoutManager);
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    rv.setAdapter(itemAdapter.wrap(fastAdapter));
    //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<>();
    int i = 0;
    for (ITypeface font : mFonts) {
        for (String icon : font.getIcons()) {
            if (i % 3 == 0) {
                models.add(new IconModel(font.getIcon(icon)));
            } else {
                models.add(new RightIconModel(font.getIcon(icon)));
            }
            i++;
        }
    }
    //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 : RightIconModel(com.mikepenz.fastadapter.app.generic.RightIconModel) IconModel(com.mikepenz.fastadapter.app.generic.IconModel) GenericIconItem(com.mikepenz.fastadapter.app.generic.GenericIconItem) RightGenericIconItem(com.mikepenz.fastadapter.app.generic.RightGenericIconItem) ArrayList(java.util.ArrayList) RightGenericIconItem(com.mikepenz.fastadapter.app.generic.RightGenericIconItem) 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) RightIconModel(com.mikepenz.fastadapter.app.generic.RightIconModel) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) Toolbar(android.support.v7.widget.Toolbar)

Example 33 with GridLayoutManager

use of android.support.v7.widget.GridLayoutManager 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);
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) IconItem(com.mikepenz.iconics.sample.item.IconItem) ITypeface(com.mikepenz.iconics.typeface.ITypeface) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 34 with GridLayoutManager

use of android.support.v7.widget.GridLayoutManager in project XRecyclerView by jianghejie.

the class XRecyclerView method setLayoutManager.

@Override
public void setLayoutManager(LayoutManager layout) {
    super.setLayoutManager(layout);
    if (mWrapAdapter != null) {
        if (layout instanceof GridLayoutManager) {
            final GridLayoutManager gridManager = ((GridLayoutManager) layout);
            gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

                @Override
                public int getSpanSize(int position) {
                    return (mWrapAdapter.isHeader(position) || mWrapAdapter.isFooter(position) || mWrapAdapter.isRefreshHeader(position)) ? gridManager.getSpanCount() : 1;
                }
            });
        }
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager)

Example 35 with GridLayoutManager

use of android.support.v7.widget.GridLayoutManager in project FastDev4Android by jiangqqlmj.

the class RecyclerViewTestActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.recyclerview_test_layout);
    top_bar_linear_back = (LinearLayout) this.findViewById(R.id.top_bar_linear_back);
    btn_add = (Button) this.findViewById(R.id.btn_add);
    btn_delete = (Button) this.findViewById(R.id.btn_delete);
    top_bar_linear_back.setOnClickListener(new CustomOnClickListener());
    btn_add.setOnClickListener(new CustomOnClickListener());
    btn_delete.setOnClickListener(new CustomOnClickListener());
    top_bar_title = (TextView) this.findViewById(R.id.top_bar_title);
    top_bar_title.setText("RecyclerView使用实例");
    //开始设置RecyclerView
    recyclerView_one = (RecyclerView) this.findViewById(R.id.recyclerView_one);
    recyclerView_one.setHasFixedSize(true);
    //1.LinearLayoutManager 线性布局类型
    mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setOrientation(OrientationHelper.VERTICAL);
    recyclerView_one.setLayoutManager(mLayoutManager);
    //2.GridLayoutManager 表格布局类型
    //        GridLayoutManager girdLayoutManager=new GridLayoutManager(this,4);
    //        recyclerView_one.setLayoutManager(girdLayoutManager);
    //3.采用StaggeredGridLayoutManager  流式布局类型
    //        StaggeredGridLayoutManager staggeredGridLayoutManager=new StaggeredGridLayoutManager(2,OrientationHelper.VERTICAL);
    //        recyclerView_one.setLayoutManager(staggeredGridLayoutManager);
    //添加默认的动画效果
    recyclerView_one.setItemAnimator(new DefaultItemAnimator());
    //添加分隔线
    recyclerView_one.addItemDecoration(new AdvanceDecoration(this, OrientationHelper.VERTICAL));
    mAdapter = new TestRecyclerAdapter(this, new TestRecyclerAdapter.OnRecyclerItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            Toast.makeText(RecyclerViewTestActivity.this, "点击了第" + position + "项", Toast.LENGTH_SHORT).show();
        }
    });
    recyclerView_one.setAdapter(mAdapter);
}
Also used : AdvanceDecoration(com.chinaztt.fda.widget.AdvanceDecoration) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) TestRecyclerAdapter(com.chinaztt.fda.adapter.TestRecyclerAdapter)

Aggregations

GridLayoutManager (android.support.v7.widget.GridLayoutManager)292 RecyclerView (android.support.v7.widget.RecyclerView)135 View (android.view.View)76 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)73 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)44 TextView (android.widget.TextView)39 BindView (butterknife.BindView)19 Toolbar (android.support.v7.widget.Toolbar)16 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)14 MaterialViewPagerHeaderDecorator (com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator)14 Nullable (android.support.annotation.Nullable)13 ImageView (android.widget.ImageView)13 ArrayList (java.util.ArrayList)13 Intent (android.content.Intent)12 Handler (android.os.Handler)12 Bundle (android.os.Bundle)11 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)11 SuppressLint (android.annotation.SuppressLint)10 Context (android.content.Context)10 Point (android.graphics.Point)9