Activity手势左滑退出

1. 简介

Activity 手势左滑退出

1.1. 特性

  1. Activity左侧滑动退出

2. 基础环境

  • AndroidStudio 3.4.+
  • java1.8
  • gradle 5.1.1

3. 如何使用

3.1. Release版本

  • 项目依赖
allprojects {
  repositories {
        maven {
               // 配置用户名和密码
               credentials {
                   username 'anonymous'
                   password ''
               }
               // 配置仓库地址
               url 'http://172.16.28.234:8083/repository/maven-releases/'
           }
  }
}
  • 添加依赖

android-support版本

    implementation 'com.jpxx.android.library:swipe-back-support:latest.integration'

3.2. 快照版本

  • 项目依赖
allprojects {
  repositories {
        maven {
               // 配置用户名和密码
               credentials {
                   username 'anonymous'
                   password ''
               }
               // 配置仓库地址
               url 'http://172.16.28.234:8083/repository/maven-snapshots/'
           }
  }
}
  • 添加依赖

android-support版本

    implementation 'com.jpxx.android.library:swipe-back-support:1.0.0-SNAPSHOT'

4. 使用说明

  1. 通过调用setSwipeBackEnable可以指定特定页面支持手势左滑
  2. 调用setSwipeBackRelated可以实现手指左滑时,页面联动滑动效果。

4.1. 基本使用

  • 基类继承SwipeBackActivity即可使用手势左滑退出功能

4.2. 已有基类,如何扩展?

  • Java
public abstract class IBaseSwipeActivity<P extends IPresenter> extends IBaseActivity<P> implements SwipeBackActivityBase {
    public boolean isSwipeBackEnabled(){
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(isSwipeBackEnabled()){
            SwipeBackHelper.onCreate(this);
            SwipeBackHelper.getCurrentPage(this)
                    .setSwipeEdgePercent(0.1F)
                    .setSwipeSensitivity(0.5f)
                    .setSwipeRelateOffset(300);
        }
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        if(isSwipeBackEnabled()){
            SwipeBackHelper.onPostCreate(this);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(isSwipeBackEnabled()){
            SwipeBackHelper.onDestroy(this);
        }
    }

    @Override
    public void setSwipeBackRelated(boolean related) {
        if(isSwipeBackEnabled()){
            SwipeBackHelper.getCurrentPage(this).setSwipeRelateEnable(related);
        }
    }

    @Override
    public void setSwipeBackEnable(boolean enable) {
        if(isSwipeBackEnabled()){
            SwipeBackHelper.getCurrentPage(this).getSwipeBackLayout().setEnableGesture(enable);
        }
    }
}
  • Kotlin
abstract class IBaseSwipeActivity<P : IPresenter> : IBaseActivity<P>(), SwipeBackActivityBase {
    override fun setupActivityComponent(appComponent: AppComponent) {
        //none
    }

    //swipe back start
    open fun isSwipeBackEnabled(): Boolean {
        return false
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        if(isSwipeBackEnabled()){
            SwipeBackHelper.onCreate(this)
            SwipeBackHelper.getCurrentPage(this)
                    .setSwipeEdgePercent(0.1f)
                    .setSwipeSensitivity(0.5f)
                    .setSwipeRelateOffset(300)
        }
        super.onCreate(savedInstanceState)
    }

    override fun onPostCreate(savedInstanceState: Bundle?) {
        super.onPostCreate(savedInstanceState)
        if(isSwipeBackEnabled()){
            SwipeBackHelper.onPostCreate(this)
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        if(isSwipeBackEnabled()){
            SwipeBackHelper.onDestroy(this)
        }
    }

    override fun setSwipeBackRelated(related: Boolean) {
        if(isSwipeBackEnabled()){
            SwipeBackHelper.getCurrentPage(this).setSwipeRelateEnable(related)
        }
    }

    override fun setSwipeBackEnable(enable: Boolean) {
        if(isSwipeBackEnabled()){
            SwipeBackHelper.getCurrentPage(this).swipeBackLayout.setEnableGesture(enable)
        }
    }
}

源码地址:http://172.16.28.234:8081/dev-plat/android/lib/swipe-back

源码地址:http://sources.jpsycn.com/dev-plat/android/lib/swipe-back.git

版权归河南金鹏信息技术股份有限公司所有,仅用于技术交流,禁止用于商业目的 all right reserved,powered by Gitbook该文件修订时间: 2020-03-21 17:17:32

results matching ""

    No results matching ""