public class

OnSwipe

extends java.lang.Object

 java.lang.Object

↳androidx.constraintlayout.motion.widget.OnSwipe

Gradle dependencies

compile group: 'androidx.constraintlayout', name: 'constraintlayout', version: '2.2.0-alpha01'

  • groupId: androidx.constraintlayout
  • artifactId: constraintlayout
  • version: 2.2.0-alpha01

Artifact androidx.constraintlayout:constraintlayout:2.2.0-alpha01 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.constraintlayout:constraintlayout com.android.support.constraint:constraint-layout

Overview

Container for holding swipe information

Summary

Fields
public static final intCOMPLETE_MODE_CONTINUOUS_VELOCITY

public static final intCOMPLETE_MODE_SPRING

public static final intDRAG_ANTICLOCKWISE

public static final intDRAG_CLOCKWISE

public static final intDRAG_DOWN

public static final intDRAG_END

public static final intDRAG_LEFT

public static final intDRAG_RIGHT

public static final intDRAG_START

public static final intDRAG_UP

public static final intFLAG_DISABLE_POST_SCROLL

public static final intFLAG_DISABLE_SCROLL

public static final intON_UP_AUTOCOMPLETE

public static final intON_UP_AUTOCOMPLETE_TO_END

public static final intON_UP_AUTOCOMPLETE_TO_START

public static final intON_UP_DECELERATE

public static final intON_UP_DECELERATE_AND_COMPLETE

public static final intON_UP_NEVER_TO_END

public static final intON_UP_NEVER_TO_START

public static final intON_UP_STOP

public static final intSIDE_BOTTOM

public static final intSIDE_END

public static final intSIDE_LEFT

public static final intSIDE_MIDDLE

public static final intSIDE_RIGHT

public static final intSIDE_START

public static final intSIDE_TOP

public static final intSPRING_BOUNDARY_BOUNCEBOTH

public static final intSPRING_BOUNDARY_BOUNCEEND

public static final intSPRING_BOUNDARY_BOUNCESTART

public static final intSPRING_BOUNDARY_OVERSHOOT

Constructors
publicOnSwipe()

Methods
public intgetAutoCompleteMode()

public intgetDragDirection()

public floatgetDragScale()

public floatgetDragThreshold()

public intgetLimitBoundsTo()

public floatgetMaxAcceleration()

public floatgetMaxVelocity()

public booleangetMoveWhenScrollAtTop()

public intgetNestedScrollFlags()

public intgetOnTouchUp()

public intgetRotationCenterId()

public intgetSpringBoundary()

The behaviour at the boundaries 0 and 1

public floatgetSpringDamping()

public floatgetSpringMass()

Get the mass of the spring.

public floatgetSpringStiffness()

get the stiffness of the spring

public floatgetSpringStopThreshold()

The threshold for spring motion to stop.

public intgetTouchAnchorId()

public intgetTouchAnchorSide()

public intgetTouchRegionId()

public voidsetAutoCompleteMode(int autoCompleteMode)

sets the behaviour at the boundaries 0 and 1 COMPLETE_MODE_CONTINUOUS_VELOCITY = 0; COMPLETE_MODE_SPRING = 1;

public OnSwipesetDragDirection(int dragDirection)

The direction of the drag.

public OnSwipesetDragScale(int dragScale)

Normally 1 this can be tweaked to make the acceleration faster

public OnSwipesetDragThreshold(int dragThreshold)

This sets the threshold before the animation is kicked off.

public OnSwipesetLimitBoundsTo(int id)

Only allow touch actions to be initiated within this region

public OnSwipesetMaxAcceleration(int maxAcceleration)

The maximum acceleration and deceleration of the animation (Change in Change in progress per second) Faster makes the object seem lighter and quicker

public OnSwipesetMaxVelocity(int maxVelocity)

The maximum velocity (Change in progress per second) animation can achieve

public OnSwipesetMoveWhenScrollAtTop(boolean moveWhenScrollAtTop)

When collaborating with a NestedScrollView do you progress form 0-1 only when the scroll view is at the top.

public OnSwipesetNestedScrollFlags(int flags)

Various flag to control behaviours of nested scroll FLAG_DISABLE_POST_SCROLL = 1; FLAG_DISABLE_SCROLL = 2;

public OnSwipesetOnTouchUp(int mode)

Configures what happens when the user releases on mouse up.

public OnSwipesetRotateCenter(int rotationCenterId)

The view to center the rotation about

public OnSwipesetSpringBoundary(int springBoundary)

The behaviour at the boundaries 0 and 1.

public OnSwipesetSpringDamping(float springDamping)

Set the damping of the spring if using spring.

public OnSwipesetSpringMass(float springMass)

Set the Mass of the spring if using spring.

public OnSwipesetSpringStiffness(float springStiffness)

set the stiffness of the spring if using spring.

public OnSwipesetSpringStopThreshold(float springStopThreshold)

set the threshold for spring motion to stop.

public OnSwipesetTouchAnchorId(int side)

The id of the view who's movement is matched to your drag If not specified it will map to a linear movement across the width of the motionLayout

public OnSwipesetTouchAnchorSide(int side)

This side of the view that matches the drag movement.

public OnSwipesetTouchRegionId(int side)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final int COMPLETE_MODE_CONTINUOUS_VELOCITY

public static final int COMPLETE_MODE_SPRING

public static final int SPRING_BOUNDARY_OVERSHOOT

public static final int SPRING_BOUNDARY_BOUNCESTART

public static final int SPRING_BOUNDARY_BOUNCEEND

public static final int SPRING_BOUNDARY_BOUNCEBOTH

public static final int DRAG_UP

public static final int DRAG_DOWN

public static final int DRAG_LEFT

public static final int DRAG_RIGHT

public static final int DRAG_START

public static final int DRAG_END

public static final int DRAG_CLOCKWISE

public static final int DRAG_ANTICLOCKWISE

public static final int FLAG_DISABLE_POST_SCROLL

public static final int FLAG_DISABLE_SCROLL

public static final int SIDE_TOP

public static final int SIDE_LEFT

public static final int SIDE_RIGHT

public static final int SIDE_BOTTOM

public static final int SIDE_MIDDLE

public static final int SIDE_START

public static final int SIDE_END

public static final int ON_UP_AUTOCOMPLETE

public static final int ON_UP_AUTOCOMPLETE_TO_START

public static final int ON_UP_AUTOCOMPLETE_TO_END

public static final int ON_UP_STOP

public static final int ON_UP_DECELERATE

public static final int ON_UP_DECELERATE_AND_COMPLETE

public static final int ON_UP_NEVER_TO_START

public static final int ON_UP_NEVER_TO_END

Constructors

public OnSwipe()

Methods

public OnSwipe setTouchAnchorId(int side)

The id of the view who's movement is matched to your drag If not specified it will map to a linear movement across the width of the motionLayout

Parameters:

side:

Returns:

public int getTouchAnchorId()

public OnSwipe setTouchAnchorSide(int side)

This side of the view that matches the drag movement. Only meaning full if the object changes size during the movement. (rotation is not considered)

Parameters:

side:

Returns:

public int getTouchAnchorSide()

public OnSwipe setDragDirection(int dragDirection)

The direction of the drag.

Parameters:

dragDirection:

Returns:

public int getDragDirection()

public OnSwipe setMaxVelocity(int maxVelocity)

The maximum velocity (Change in progress per second) animation can achieve

Parameters:

maxVelocity:

Returns:

public float getMaxVelocity()

public OnSwipe setMaxAcceleration(int maxAcceleration)

The maximum acceleration and deceleration of the animation (Change in Change in progress per second) Faster makes the object seem lighter and quicker

Parameters:

maxAcceleration:

Returns:

public float getMaxAcceleration()

public OnSwipe setMoveWhenScrollAtTop(boolean moveWhenScrollAtTop)

When collaborating with a NestedScrollView do you progress form 0-1 only when the scroll view is at the top.

Parameters:

moveWhenScrollAtTop:

Returns:

public boolean getMoveWhenScrollAtTop()

public OnSwipe setDragScale(int dragScale)

Normally 1 this can be tweaked to make the acceleration faster

Parameters:

dragScale:

Returns:

public float getDragScale()

public OnSwipe setDragThreshold(int dragThreshold)

This sets the threshold before the animation is kicked off. It is important when have multi state animations the have some play before the System decides which animation to jump on.

Parameters:

dragThreshold:

Returns:

public float getDragThreshold()

public OnSwipe setTouchRegionId(int side)

Parameters:

side:

Returns:

public int getTouchRegionId()

public OnSwipe setOnTouchUp(int mode)

Configures what happens when the user releases on mouse up. One of: ON_UP_AUTOCOMPLETE, ON_UP_AUTOCOMPLETE_TO_START, ON_UP_AUTOCOMPLETE_TO_END, ON_UP_STOP, ON_UP_DECELERATE, ON_UP_DECELERATE_AND_COMPLETE

Parameters:

mode: default = ON_UP_AUTOCOMPLETE

Returns:

public int getOnTouchUp()

public OnSwipe setNestedScrollFlags(int flags)

Various flag to control behaviours of nested scroll FLAG_DISABLE_POST_SCROLL = 1; FLAG_DISABLE_SCROLL = 2;

Parameters:

flags:

Returns:

public int getNestedScrollFlags()

public OnSwipe setLimitBoundsTo(int id)

Only allow touch actions to be initiated within this region

Parameters:

id:

Returns:

public int getLimitBoundsTo()

public OnSwipe setRotateCenter(int rotationCenterId)

The view to center the rotation about

Parameters:

rotationCenterId:

Returns:

this

public int getRotationCenterId()

public float getSpringDamping()

public OnSwipe setSpringDamping(float springDamping)

Set the damping of the spring if using spring. c in "a = (-k*x-c*v)/m" equation for the acceleration of a spring

Parameters:

springDamping:

Returns:

this

public float getSpringMass()

Get the mass of the spring. the m in "a = (-k*x-c*v)/m" equation for the acceleration of a spring

Returns:

public OnSwipe setSpringMass(float springMass)

Set the Mass of the spring if using spring. m in "a = (-k*x-c*v)/m" equation for the acceleration of a spring

Parameters:

springMass:

Returns:

this

public float getSpringStiffness()

get the stiffness of the spring

Returns:

NaN if not set

public OnSwipe setSpringStiffness(float springStiffness)

set the stiffness of the spring if using spring. If this is set the swipe will use a spring return system. If set to NaN it will revert to the norm system. K in "a = (-k*x-c*v)/m" equation for the acceleration of a spring

Parameters:

springStiffness:

Returns:

public float getSpringStopThreshold()

The threshold for spring motion to stop.

Returns:

public OnSwipe setSpringStopThreshold(float springStopThreshold)

set the threshold for spring motion to stop. This is in change in progress / second If the spring will never go above that threshold again it will stop.

Parameters:

springStopThreshold:

Returns:

public int getSpringBoundary()

The behaviour at the boundaries 0 and 1

Returns:

public OnSwipe setSpringBoundary(int springBoundary)

The behaviour at the boundaries 0 and 1. SPRING_BOUNDARY_OVERSHOOT = 0; SPRING_BOUNDARY_BOUNCE_START = 1; SPRING_BOUNDARY_BOUNCE_END = 2; SPRING_BOUNDARY_BOUNCE_BOTH = 3;

Parameters:

springBoundary:

Returns:

public int getAutoCompleteMode()

public void setAutoCompleteMode(int autoCompleteMode)

sets the behaviour at the boundaries 0 and 1 COMPLETE_MODE_CONTINUOUS_VELOCITY = 0; COMPLETE_MODE_SPRING = 1;

Source

/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.constraintlayout.motion.widget;

/**
 * Container for holding swipe information
 */
public class OnSwipe {
    private int mDragDirection = 0;
    private int mTouchAnchorSide = 0;
    private int mTouchAnchorId = MotionScene.UNSET;
    private int mTouchRegionId = MotionScene.UNSET;
    private int mLimitBoundsTo = MotionScene.UNSET;
    private int mOnTouchUp = 0;
    private int mRotationCenterId = MotionScene.UNSET;
    private float mMaxVelocity = 4;
    private float mMaxAcceleration = 1.2f;
    private boolean mMoveWhenScrollAtTop = true;
    private float mDragScale = 1f;
    private int mFlags = 0;
    private float mDragThreshold = 10;
    private float mSpringDamping = Float.NaN;
    private float mSpringMass = 1;
    private float mSpringStiffness = Float.NaN;
    private float mSpringStopThreshold = Float.NaN;
    private int mSpringBoundary = 0;
    private int mAutoCompleteMode = 0;

    public static final int COMPLETE_MODE_CONTINUOUS_VELOCITY = 0;
    public static final int COMPLETE_MODE_SPRING = 1;

    public static final int SPRING_BOUNDARY_OVERSHOOT = 0;
    public static final int SPRING_BOUNDARY_BOUNCESTART = 1;
    public static final int SPRING_BOUNDARY_BOUNCEEND = 2;
    public static final int SPRING_BOUNDARY_BOUNCEBOTH = 3;
    public static final int DRAG_UP = 0;
    public static final int DRAG_DOWN = 1;
    public static final int DRAG_LEFT = 2;
    public static final int DRAG_RIGHT = 3;
    public static final int DRAG_START = 4;
    public static final int DRAG_END = 5;
    public static final int DRAG_CLOCKWISE = 6;
    public static final int DRAG_ANTICLOCKWISE = 7;

    public static final int FLAG_DISABLE_POST_SCROLL = 1;
    public static final int FLAG_DISABLE_SCROLL = 2;

    public static final int SIDE_TOP = 0;
    public static final int SIDE_LEFT = 1;
    public static final int SIDE_RIGHT = 2;
    public static final int SIDE_BOTTOM = 3;
    public static final int SIDE_MIDDLE = 4;
    public static final int SIDE_START = 5;
    public static final int SIDE_END = 6;

    public static final int ON_UP_AUTOCOMPLETE = 0;
    public static final int ON_UP_AUTOCOMPLETE_TO_START = 1;
    public static final int ON_UP_AUTOCOMPLETE_TO_END = 2;
    public static final int ON_UP_STOP = 3;
    public static final int ON_UP_DECELERATE = 4;
    public static final int ON_UP_DECELERATE_AND_COMPLETE = 5;
    public static final int ON_UP_NEVER_TO_START = 6;
    public static final int ON_UP_NEVER_TO_END = 7;

    /**
     * The id of the view who's movement is matched to your drag
     * If not specified it will map to a linear movement across the width of the motionLayout
     *
     * @param side
     * @return
     */
    public OnSwipe setTouchAnchorId(int side) {
        mTouchAnchorId = side;
        return this;
    }

    public int getTouchAnchorId() {
        return mTouchAnchorId;
    }

    /**
     * This side of the view that matches the drag movement.
     * Only meaning full if the object changes size during the movement.
     * (rotation is not considered)
     *
     * @param side
     * @return
     */
    public OnSwipe setTouchAnchorSide(int side) {
        mTouchAnchorSide = side;
        return this;
    }

    public int getTouchAnchorSide() {
        return mTouchAnchorSide;
    }

    /**
     * The direction of the drag.
     *
     * @param dragDirection
     * @return
     */
    public OnSwipe setDragDirection(int dragDirection) {
        mDragDirection = dragDirection;
        return this;
    }

    public int getDragDirection() {
        return mDragDirection;
    }

    /**
     * The maximum velocity (Change in progress per second) animation can achieve
     *
     * @param maxVelocity
     * @return
     */
    public OnSwipe setMaxVelocity(int maxVelocity) {
        mMaxVelocity = maxVelocity;
        return this;
    }

    public float getMaxVelocity() {
        return mMaxVelocity;
    }

    /**
     * The maximum acceleration and deceleration of the animation
     * (Change in Change in progress per second)
     * Faster makes the object seem lighter and quicker
     *
     * @param maxAcceleration
     * @return
     */
    public OnSwipe setMaxAcceleration(int maxAcceleration) {
        mMaxAcceleration = maxAcceleration;
        return this;
    }

    public float getMaxAcceleration() {
        return mMaxAcceleration;
    }

    /**
     * When collaborating with a NestedScrollView do you progress form 0-1 only
     * when the scroll view is at the top.
     *
     * @param moveWhenScrollAtTop
     * @return
     */
    public OnSwipe setMoveWhenScrollAtTop(boolean moveWhenScrollAtTop) {
        mMoveWhenScrollAtTop = moveWhenScrollAtTop;
        return this;
    }

    public boolean getMoveWhenScrollAtTop() {
        return mMoveWhenScrollAtTop;
    }

    /**
     * Normally 1 this can be tweaked to make the acceleration faster
     *
     * @param dragScale
     * @return
     */
    public OnSwipe setDragScale(int dragScale) {
        mDragScale = dragScale;
        return this;
    }

    public float getDragScale() {
        return mDragScale;
    }

    /**
     * This sets the threshold before the animation is kicked off.
     * It is important when have multi state animations the have some play before the
     * System decides which animation to jump on.
     *
     * @param dragThreshold
     * @return
     */
    public OnSwipe setDragThreshold(int dragThreshold) {
        mDragThreshold = dragThreshold;
        return this;
    }

    public float getDragThreshold() {
        return mDragThreshold;
    }

    /**
     * @param side
     * @return
     */
    public OnSwipe setTouchRegionId(int side) {
        mTouchRegionId = side;
        return this;
    }

    public int getTouchRegionId() {
        return mTouchRegionId;
    }

    /**
     * Configures what happens when the user releases on mouse up.
     * One of: ON_UP_AUTOCOMPLETE, ON_UP_AUTOCOMPLETE_TO_START, ON_UP_AUTOCOMPLETE_TO_END,
     * ON_UP_STOP, ON_UP_DECELERATE, ON_UP_DECELERATE_AND_COMPLETE
     *
     * @param mode default = ON_UP_AUTOCOMPLETE
     * @return
     */
    public OnSwipe setOnTouchUp(int mode) {
        mOnTouchUp = mode;
        return this;
    }

    public int getOnTouchUp() {
        return mOnTouchUp;
    }

    /**
     * Various flag to control behaviours of nested scroll
     * FLAG_DISABLE_POST_SCROLL = 1;
     * FLAG_DISABLE_SCROLL = 2;
     *
     * @param flags
     * @return
     */
    public OnSwipe setNestedScrollFlags(int flags) {
        mFlags = flags;
        return this;
    }

    public int getNestedScrollFlags() {
        return mFlags;
    }

    /**
     * Only allow touch actions to be initiated within this region
     *
     * @param id
     * @return
     */
    public OnSwipe setLimitBoundsTo(int id) {
        mLimitBoundsTo = id;
        return this;
    }

    public int getLimitBoundsTo() {
        return mLimitBoundsTo;
    }

    /**
     * The view to center the rotation about
     *
     * @param rotationCenterId
     * @return this
     */
    public OnSwipe setRotateCenter(int rotationCenterId) {
        mRotationCenterId = rotationCenterId;
        return this;
    }

    public int getRotationCenterId() {
        return mRotationCenterId;
    }


    public float getSpringDamping() {
        return mSpringDamping;
    }

    /**
     * Set the damping of the spring if using spring.
     * c in "a = (-k*x-c*v)/m" equation for the acceleration of a spring
     *
     * @param springDamping
     * @return this
     */
    public OnSwipe setSpringDamping(float springDamping) {
        mSpringDamping = springDamping;
        return this;
    }

    /**
     * Get the mass of the spring.
     * the m in "a = (-k*x-c*v)/m" equation for the acceleration of a spring
     *
     * @return
     */
    public float getSpringMass() {
        return mSpringMass;
    }

    /**
     * Set the Mass of the spring if using spring.
     * m in "a = (-k*x-c*v)/m" equation for the acceleration of a spring
     *
     * @param springMass
     * @return this
     */
    public OnSwipe setSpringMass(float springMass) {
        mSpringMass = springMass;
        return this;
    }

    /**
     * get the stiffness of the spring
     *
     * @return NaN if not set
     */
    public float getSpringStiffness() {
        return mSpringStiffness;
    }

    /**
     * set the stiffness of the spring if using spring.
     * If this is set the swipe will use a spring return system.
     * If set to NaN it will revert to the norm system.
     * K in "a = (-k*x-c*v)/m" equation for the acceleration of a spring
     *
     * @param springStiffness
     * @return
     */
    public OnSwipe setSpringStiffness(float springStiffness) {
        mSpringStiffness = springStiffness;
        return this;
    }

    /**
     * The threshold for spring motion to stop.
     *
     * @return
     */
    public float getSpringStopThreshold() {
        return mSpringStopThreshold;
    }

    /**
     * set the threshold for spring motion to stop.
     * This is in change in progress / second
     * If the spring will never go above that threshold again it will stop.
     *
     * @param springStopThreshold
     * @return
     */
    public OnSwipe setSpringStopThreshold(float springStopThreshold) {
        mSpringStopThreshold = springStopThreshold;
        return this;
    }

    /**
     * The behaviour at the boundaries 0 and 1
     *
     * @return
     */
    public int getSpringBoundary() {
        return mSpringBoundary;
    }

    /**
     * The behaviour at the boundaries 0 and 1.
     * SPRING_BOUNDARY_OVERSHOOT = 0;
     * SPRING_BOUNDARY_BOUNCE_START = 1;
     * SPRING_BOUNDARY_BOUNCE_END = 2;
     * SPRING_BOUNDARY_BOUNCE_BOTH = 3;
     *
     * @param springBoundary
     * @return
     */
    public OnSwipe setSpringBoundary(int springBoundary) {
        mSpringBoundary = springBoundary;
        return this;
    }

    public int getAutoCompleteMode() {
        return mAutoCompleteMode;
    }


    /**
     * sets the behaviour at the boundaries 0 and 1
     *     COMPLETE_MODE_CONTINUOUS_VELOCITY = 0;
     *      COMPLETE_MODE_SPRING = 1;
     *
     */
    public void setAutoCompleteMode(int autoCompleteMode) {
        mAutoCompleteMode =  autoCompleteMode;
    }

}