Giter Club home page Giter Club logo

swipe-touch-listener's Introduction

swipe-touch-listener

Simple touch listener for swiping gestures.

presentation gif

Getting Started

Installing

Add to your .gradle file

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
    
dependencies {
        implementation 'com.github.colorgreen:swipe-touch-listener:v1.3'
}

Usage

  • First create listener
OnSwipeTouchListener listener = new OnSwipeTouchListener();
  • Then create SwipeAction
SwipeAction swipeAction = new SwipeAction();
  • Create listener
swipeAction.setSwipeActionListener( new SwipeActionListener() {
    @Override
    public void onDragStart( float val, float totalFriction ) {}

    @Override
    public void onDrag( float val, float friction ) {
        bar.setLayoutParams( new RelativeLayout.LayoutParams( bar.getWidth(), (int) val ) );
        bar.setBackgroundColor( interpolateColor( lightBlue, darkBlue, val / targetHeight ) );
    }

    @Override
    public void onDragEnd( float val, float totalFriction ) {
        // use setBlocked() for blocking another panels from extending
        bottomSwipeAction.setBlocked( swipeAction.isExtended() );
    }
} );

You can override functions like onDragStart, onDrag and onDragEnd. onDragEnd is invoked only when val reach step. Set properties for action.

swipeAction.setDirection( SwipeAction.DragDirection.Down );
swipeAction.setSteps( new float[]{ startBarHeight, targetHeight * 0.3f, targetHeight } );
swipeAction.setDragThreshold( 0.4f );

Threshold is distance in percent between steps above which we accept drag and value will be automatically animated to next step. For example steps are [ 200,700 ], threshold is 0.2f, so if we drag over 300 ( (700-200)*0.2f) ) value will be animated to 700, else back to 300.

  • Add action to listener
listener.addAction( swipeAction );

We can add multiple actions to listener. See example app for this case. But no more than one view can be extended simultaneously.

  • And attach listener to view
listener.attachToView( view );
//... or
view.setOnTouchListener( listener );

Other functions

  • setBlocked( boolean )
  • pushToStep( int stepIndex )
  • expand()
  • collapse()
  • isExtended()

Authors

@colorgreen

Version History

  • v1.4
    • Changed to raw axis (no problem on moving panel with attached OnSwipeTouchListener)
    • javadoc support
  • v1.3
    • Swipe action is based now on listener
    • Addes expand, collapse and pushToStep method which allow to control elements without swipe
  • v1.2
    • Friction fix
  • v1.1
    • Added friction in onDrag
  • v1.0
    • Initial Release

Licence

Free to use

swipe-touch-listener's People

Contributors

colorgreen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.