Search in sources :

Example 1 with FanLayoutManager

use of com.cleveroad.fanlayoutmanager.FanLayoutManager in project FanLayoutManager by Cleveroad.

the class MainFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.rvCards);
    FanLayoutManagerSettings fanLayoutManagerSettings = FanLayoutManagerSettings.newBuilder(getContext()).withFanRadius(true).withAngleItemBounce(5).withViewHeightDp(160).withViewWidthDp(120).build();
    fanLayoutManager = new FanLayoutManager(getContext(), fanLayoutManagerSettings);
    recyclerView.setLayoutManager(fanLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    adapter = new SportCardsAdapter(getContext());
    adapter.addAll(SportCardsUtils.generateSportCards());
    adapter.setOnItemClickListener(new SportCardsAdapter.OnItemClickListener() {

        @Override
        public void onItemClicked(int itemPosition, final View view) {
            if (fanLayoutManager.getSelectedItemPosition() != itemPosition) {
                fanLayoutManager.switchItem(recyclerView, itemPosition);
            } else {
                fanLayoutManager.straightenSelectedItem(new Animator.AnimatorListener() {

                    @Override
                    public void onAnimationStart(Animator animator) {
                    }

                    @Override
                    public void onAnimationEnd(Animator animator) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                            onClick(view, fanLayoutManager.getSelectedItemPosition());
                        } else {
                            onClick(fanLayoutManager.getSelectedItemPosition());
                        }
                    }

                    @Override
                    public void onAnimationCancel(Animator animator) {
                    }

                    @Override
                    public void onAnimationRepeat(Animator animator) {
                    }
                });
            }
        }
    });
    recyclerView.setAdapter(adapter);
    recyclerView.setChildDrawingOrderCallback(new FanChildDrawingOrderCallback(fanLayoutManager));
    (view.findViewById(R.id.logo)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            fanLayoutManager.collapseViews();
        }
    });
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Animator(android.animation.Animator) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) FanLayoutManagerSettings(com.cleveroad.fanlayoutmanager.FanLayoutManagerSettings) FanLayoutManager(com.cleveroad.fanlayoutmanager.FanLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) FanChildDrawingOrderCallback(com.cleveroad.fanlayoutmanager.callbacks.FanChildDrawingOrderCallback)

Aggregations

Animator (android.animation.Animator)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 FanLayoutManager (com.cleveroad.fanlayoutmanager.FanLayoutManager)1 FanLayoutManagerSettings (com.cleveroad.fanlayoutmanager.FanLayoutManagerSettings)1 FanChildDrawingOrderCallback (com.cleveroad.fanlayoutmanager.callbacks.FanChildDrawingOrderCallback)1