Search in sources :

Example 1 with OnDismissListener

use of com.google.android.material.behavior.SwipeDismissBehavior.OnDismissListener in project ods-android by Orange-OpenSource.

the class CardSwipeDismissFragment method onCreateDemoView.

/**
 * Inflate fragment view and setup with {@link SwipeDismissBehavior}
 */
@Override
public View onCreateDemoView(LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
    View view = layoutInflater.inflate(R.layout.cat_card_swipe_fragment, viewGroup, false);
    CoordinatorLayout container = view.findViewById(R.id.card_container);
    SwipeDismissBehavior<View> swipeDismissBehavior = new SwipeDismissBehavior<>();
    swipeDismissBehavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_START_TO_END);
    MaterialCardView cardContentLayout = view.findViewById(R.id.card_content_layout);
    CoordinatorLayout.LayoutParams coordinatorParams = (CoordinatorLayout.LayoutParams) cardContentLayout.getLayoutParams();
    coordinatorParams.setBehavior(swipeDismissBehavior);
    swipeDismissBehavior.setListener(new OnDismissListener() {

        @Override
        public void onDismiss(View view) {
            Snackbar.make(container, R.string.cat_card_dismissed, Snackbar.LENGTH_INDEFINITE).setAction(R.string.cat_card_undo, v -> resetCard(cardContentLayout)).show();
        }

        @Override
        public void onDragStateChanged(int state) {
            CardSwipeDismissFragment.onDragStateChanged(state, cardContentLayout);
        }
    });
    return view;
}
Also used : CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) MaterialCardView(com.google.android.material.card.MaterialCardView) SwipeDismissBehavior(com.google.android.material.behavior.SwipeDismissBehavior) OnDismissListener(com.google.android.material.behavior.SwipeDismissBehavior.OnDismissListener) MaterialCardView(com.google.android.material.card.MaterialCardView) View(android.view.View)

Aggregations

View (android.view.View)1 CoordinatorLayout (androidx.coordinatorlayout.widget.CoordinatorLayout)1 SwipeDismissBehavior (com.google.android.material.behavior.SwipeDismissBehavior)1 OnDismissListener (com.google.android.material.behavior.SwipeDismissBehavior.OnDismissListener)1 MaterialCardView (com.google.android.material.card.MaterialCardView)1