Skip to content

SwipeDirectionalView(Swipe Directions), Swipe Touch Callback, Animated Undo, Programmatically Expand/Collapse ExpandablePlaceHolderView

Compare
Choose a tag to compare
@janishar janishar released this 09 Aug 18:02

SwipeDirectionalView

0.7.0 version provides SwipeDirectionalView class, which is build on top of SwipePlaceHolderView. This View provides more refines directional callbacks for the swipes. All the properties of SwipePlaceHolderView is available to SwipeDirectionalView.

Usage:

    <com.mindorks.placeholderview.SwipeDirectionalView
        android:id="@+id/swipeView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
private SwipeDirectionalView mSwipeView;
...

mSwipeView.getBuilder()
                .setSwipeVerticalThreshold(Utils.dpToPx(50))
                .setSwipeHorizontalThreshold(Utils.dpToPx(50))
                ...

setSwipeVerticalThreshold: It defines the vertical area from the initial touch location.
setSwipeHorizontalThreshold: It defines the horizontal area from the initial touch location.

If the swipe take place within these areas then it will be considered for TOP, BOTTOM, LEFT or RIGHT direction swipe else the direction will be RIGHT_TOP, RIGHT_BOTTOM, LEFT_TOP or LEFT_BOTTOM

For receiving the directional callbacks for SwipeDirectionalView, new Annotations has been added:

  1. @SwipeOutDirectional: It is called when the card is either left swiped or top swiped.
    @SwipeOutDirectional
    private void onSwipeOutDirectional(SwipeDirection direction) {
        Log.d("DEBUG", "SwipeOutDirectional " + direction.name());
    }
  1. @SwipeInDirectional: It is called when the card is either right swiped or bottom swiped.
    @SwipeInDirectional
    private void onSwipeInDirectional(SwipeDirection direction) {
        Log.d("DEBUG", "SwipeInDirectional " + direction.name());
    }
  1. @SwipingDirection: It is called when the card is swiping in some direction.
    @SwipingDirection
    private void onSwipingDirection(SwipeDirection direction) {
        Log.d("DEBUG", "SwipingDirection " + direction.name());
    }

Refer to this demo example to understand it's usage: Link

SwipeTouch Callback

This callback is added to SwipePlaceHolderView. It provides the starting and current touch point's coordinates on the card while it is getting swiped.

    @SwipeTouch
    private void onSwipeTouch(float xStart, float yStart, float xCurrent, float yCurrent) {
        Log.d("DEBUG", "onSwipeTouch "
                + " xStart : " + xStart
                + " yStart : " + yStart
                + " xCurrent : " + xCurrent
                + " yCurrent : " + yCurrent
                + " distance : "
                + Math.sqrt(Math.pow(xCurrent - xStart, 2) + (Math.pow(yCurrent - yStart, 2)))
        );
    }

Programmatic undo for SwipePlaceHolderView with Animation.

The mSwipeView.undoLastSwipe(); will now put back the swiped card back into the stack by making a reverse animation.

Programmatic Expand/Collapse for ExpandablePlaceHolderView

// These will expand the desired parent
public <T> void expand(T resolver) throws Resources.NotFoundException
public void expand(int position) throws Resources.NotFoundException

// These will collapse the desired parent
public <T> void collapse(T resolver) throws Resources.NotFoundException
public void collapse(int position) throws Resources.NotFoundException

// This will collapse all the expanded parents
public void collapseAll()

//Example
    @OnClick(R.id.collapse)
    void onCollapse() {
        try {
            mExpandableView.collapse(parentItem);
           //mExpandableView.collapse(0);
        } catch (Resources.NotFoundException e) {
            e.printStackTrace();
        }
    }