Search in sources :

Example 86 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project SherlockAdapter by EvilBT.

the class ExpandableActivity method initView.

private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mRecyclerView = (RecyclerView) findViewById(R.id.list);
    mGridLayoutManager = new GridLayoutManager(this, 2);
    mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mStaggeredGridLayoutManager);
    mAdapter = new MyExpandableAdapter();
    // mAdapter.setAlwaysShowFoot(true);
    // mAdapter.setAlwaysShowHead(true);
    mAdapter.addHeadLayout(R.layout.item_head);
    mAdapter.addFootLayout(R.layout.item_foot2);
    // 设置DiffUtil效果
    mAdapter.setCallback(new DiffUtilCallback<IMultiItem>() {

        @Override
        public boolean areItemsTheSame(IMultiItem oldItem, IMultiItem newItem) {
            if (oldItem instanceof ImageLabel && newItem instanceof ImageLabel) {
                return TextUtils.equals(((ImageLabel) oldItem).getData(), ((ImageLabel) newItem).getData());
            }
            if (oldItem instanceof Card && newItem instanceof Card) {
                return ((Card) oldItem).getData().mImageResId == ((Card) newItem).getData().mImageResId;
            }
            return false;
        }

        @Override
        public boolean areContentsTheSame(IMultiItem oldItem, IMultiItem newItem) {
            if (oldItem instanceof ImageLabel && newItem instanceof ImageLabel) {
                return true;
            }
            if (oldItem instanceof Card && newItem instanceof Card) {
                return TextUtils.equals(((Card) oldItem).getData().mImageTitle, ((Card) newItem).getData().mImageTitle);
            }
            return false;
        }
    });
    mRecyclerView.setAdapter(mAdapter);
    // 屏障默认的Change动画
    ((SimpleItemAnimator) mRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
    // 点击展开/折叠事件
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(@NonNull View view, int adapterPosition) {
            if (view.getId() == R.id.label_root) {
                IMultiItem item = mAdapter.getData(adapterPosition);
                if (item instanceof IExpandable) {
                    IExpandable expandable = (IExpandable) item;
                    if (expandable.isExpandable()) {
                        // 修复issue#2
                        // 这个支持包的bug: https://issuetracker.google.com/issues/37034096
                        mStaggeredGridLayoutManager.invalidateSpanAssignments();
                        mAdapter.collapseAll(adapterPosition);
                    } else {
                        mAdapter.expandAll(adapterPosition);
                    }
                }
            }
        }
    });
    mAdapter.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(@NonNull View view, int adapterPosition) {
            mAdapter.removeData(adapterPosition);
            return true;
        }
    });
    final SwipeRefreshLayout refresh = (SwipeRefreshLayout) findViewById(R.id.refresh);
    refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refreshData();
            refresh.setRefreshing(false);
        }
    });
    findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            refreshData();
        }
    });
    initData();
}
Also used : SimpleItemAnimator(androidx.recyclerview.widget.SimpleItemAnimator) OnItemClickListener(xyz.zpayh.adapter.OnItemClickListener) ImageLabel(xyz.zpayh.myadapter.data.ImageLabel) IExpandable(xyz.zpayh.adapter.IExpandable) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) IMultiItem(xyz.zpayh.adapter.IMultiItem) OnItemLongClickListener(xyz.zpayh.adapter.OnItemLongClickListener) Card(xyz.zpayh.myadapter.data.Card) ImageCard(xyz.zpayh.myadapter.data.ImageCard) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) MyExpandableAdapter(xyz.zpayh.myadapter.adapter.MyExpandableAdapter) Toolbar(androidx.appcompat.widget.Toolbar)

Example 87 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project android_packages_apps_crDroidSettings by crdroidandroid.

the class FontsPicker method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.item_view, container, false);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 1);
    mRecyclerView.setLayoutManager(gridLayoutManager);
    Adapter mAdapter = new Adapter(getActivity());
    mRecyclerView.setAdapter(mAdapter);
    return view;
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView)

Example 88 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project android_packages_apps_crDroidSettings by crdroidandroid.

the class IconShapes method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.item_view, container, false);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3);
    mRecyclerView.setLayoutManager(gridLayoutManager);
    Adapter mAdapter = new Adapter(getActivity());
    mRecyclerView.setAdapter(mAdapter);
    return view;
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView)

Example 89 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project android_packages_apps_crDroidSettings by crdroidandroid.

the class NavbarStyles method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.item_view, container, false);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2);
    mRecyclerView.setLayoutManager(gridLayoutManager);
    Adapter mAdapter = new Adapter(getActivity());
    mRecyclerView.setAdapter(mAdapter);
    return view;
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView)

Example 90 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project android_packages_apps_crDroidSettings by crdroidandroid.

the class SignalIcons method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.item_view, container, false);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3);
    mRecyclerView.setLayoutManager(gridLayoutManager);
    Adapter mAdapter = new Adapter(getActivity());
    mRecyclerView.setAdapter(mAdapter);
    return view;
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView)

Aggregations

GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)122 RecyclerView (androidx.recyclerview.widget.RecyclerView)63 View (android.view.View)45 TextView (android.widget.TextView)19 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)16 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)13 ImageView (android.widget.ImageView)12 Nullable (androidx.annotation.Nullable)11 Toolbar (androidx.appcompat.widget.Toolbar)10 ViewGroup (android.view.ViewGroup)7 SmoothScrollGridLayoutManager (eu.davidea.flexibleadapter.common.SmoothScrollGridLayoutManager)7 SuppressLint (android.annotation.SuppressLint)6 Context (android.content.Context)6 ArrayList (java.util.ArrayList)6 NonNull (androidx.annotation.NonNull)5 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)5 List (java.util.List)5 RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)5 Drawable (android.graphics.drawable.Drawable)4 Handler (android.os.Handler)3