SwipeListener

可以通过swipeConsumer.addListener(listener)来监听该SwipeConsumer对象的运行状态

可以对同一个SwipeConsumer对象多次调用addListener(listener)来添加多个监听对象,并按照添加的顺序执行回调

接口定义

/**
 * listen swipe state of {@link SwipeConsumer} via {@link SwipeConsumer#addListener(SwipeListener)}
 * @author billy.qi
 * @see SimpleSwipeListener
 */
public interface SwipeListener {
    void onConsumerAttachedToWrapper(SmartSwipeWrapper wrapper, SwipeConsumer consumer);
    void onConsumerDetachedFromWrapper(SmartSwipeWrapper wrapper, SwipeConsumer consumer);
    void onSwipeStateChanged(SmartSwipeWrapper wrapper, SwipeConsumer consumer, int state, int direction, float progress);
    void onSwipeStart(SmartSwipeWrapper wrapper, SwipeConsumer consumer, int direction);
    void onSwipeProcess(SmartSwipeWrapper wrapper, SwipeConsumer consumer, int direction, boolean settling, float progress);
    void onSwipeRelease(SmartSwipeWrapper wrapper, SwipeConsumer consumer, int direction, float progress, float xVelocity, float yVelocity);
    void onSwipeOpened(SmartSwipeWrapper wrapper, SwipeConsumer consumer, int direction);
    void onSwipeClosed(SmartSwipeWrapper wrapper, SwipeConsumer consumer, int direction);
}

Tips

SmartSwipe为SwipeListener接口提供了一个空实现类:SimpleSwipeListener, 只需要个别状态回调时可继承此类,从而使得代码更简洁

回调顺序

  1. 手势打开/关闭
    onSwipeStart
    onSwipeStateChanged (state = 1)
    onSwipeProcess(0个或多个, settling=false)
    onSwipeRelease
    onSwipeOpened(这个open状态回调需要满足2个条件:抬起手指时滑动距离>=mOpenDistance、释放模式为RELEASE_MODE_AUTO_CLOSE)
    onSwipeStateChanged (state = 2)
    onSwipeProcess(0个或多个, settling=true)
    onSwipeStateChanged (state = 0)
    onSwipeOpened/onSwipeClosed
    
  2. 自动打开/关闭
    onSwipeStart
    onSwipeStateChanged (state = 2)
    onSwipeProcess(多个, settling=true)
    onSwipeStateChanged (state = 0)
    onSwipeOpened/onSwipeClosed
    

简单示例

SmartSwipe.wrap(SwipeBackBezierConsumerActivity.this)
    .addConsumer(new BezierBackConsumer())
    .enableLeft()
    .addListener(new SimpleSwipeListener() {
        @Override
        public void onSwipeOpened(SmartSwipeWrapper wrapper, SwipeConsumer consumer, int direction) {
            finish();
        }
    })
Copyright © qibilly.com 2019 all right reserved,powered by Gitbook最后修改时间: 2019-07-12 15:56:20

results matching ""

    No results matching ""