public class

OnSwipe

extends java.lang.Object

 java.lang.Object

↳androidx.constraintlayout.core.dsl.OnSwipe

Gradle dependencies

compile group: 'androidx.constraintlayout', name: 'constraintlayout-core', version: '1.1.0-beta01'

  • groupId: androidx.constraintlayout
  • artifactId: constraintlayout-core
  • version: 1.1.0-beta01

Artifact androidx.constraintlayout:constraintlayout-core:1.1.0-beta01 it located at Google repository (https://maven.google.com/)

Overview

Create automatic swipe handling object

Summary

Fields
public static final intFLAG_DISABLE_POST_SCROLL

public static final intFLAG_DISABLE_SCROLL

Constructors
publicOnSwipe()

publicOnSwipe(java.lang.String anchor, OnSwipe.Side side, OnSwipe.Drag dragDirection)

Methods
public OnSwipe.ModegetAutoCompleteMode()

public OnSwipe.DraggetDragDirection()

public floatgetDragScale()

public floatgetDragThreshold()

public java.lang.StringgetLimitBoundsTo()

public floatgetMaxAcceleration()

public floatgetMaxVelocity()

public OnSwipe.TouchUpgetOnTouchUp()

public java.lang.StringgetRotationCenterId()

public OnSwipe.BoundarygetSpringBoundary()

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 java.lang.StringgetTouchAnchorId()

public OnSwipe.SidegetTouchAnchorSide()

public voidsetAutoCompleteMode(OnSwipe.Mode autoCompleteMode)

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

public OnSwipesetDragDirection(OnSwipe.Drag 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(java.lang.String 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 OnSwipesetOnTouchUp(OnSwipe.TouchUp mode)

Configures what happens when the user releases on mouse up.

public OnSwipesetRotateCenter(java.lang.String rotationCenterId)

The view to center the rotation about

public OnSwipesetSpringBoundary(OnSwipe.Boundary 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(java.lang.String id)

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(OnSwipe.Side side)

This side of the view that matches the drag movement.

public java.lang.StringtoString()

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

Fields

public static final int FLAG_DISABLE_POST_SCROLL

public static final int FLAG_DISABLE_SCROLL

Constructors

public OnSwipe()

public OnSwipe(java.lang.String anchor, OnSwipe.Side side, OnSwipe.Drag dragDirection)

Methods

public OnSwipe setTouchAnchorId(java.lang.String id)

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 java.lang.String getTouchAnchorId()

public OnSwipe setTouchAnchorSide(OnSwipe.Side 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)

public OnSwipe.Side getTouchAnchorSide()

public OnSwipe setDragDirection(OnSwipe.Drag dragDirection)

The direction of the drag.

public OnSwipe.Drag getDragDirection()

public OnSwipe setMaxVelocity(int maxVelocity)

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

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

public float getMaxAcceleration()

public OnSwipe setDragScale(int dragScale)

Normally 1 this can be tweaked to make the acceleration faster

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.

public float getDragThreshold()

public OnSwipe setOnTouchUp(OnSwipe.TouchUp 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

public OnSwipe.TouchUp getOnTouchUp()

public OnSwipe setLimitBoundsTo(java.lang.String id)

Only allow touch actions to be initiated within this region

public java.lang.String getLimitBoundsTo()

public OnSwipe setRotateCenter(java.lang.String rotationCenterId)

The view to center the rotation about

Returns:

this

public java.lang.String 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

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

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

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

public float getSpringStopThreshold()

The threshold for spring motion to stop.

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: when to stop.

public OnSwipe.Boundary getSpringBoundary()

The behaviour at the boundaries 0 and 1

public OnSwipe setSpringBoundary(OnSwipe.Boundary springBoundary)

The behaviour at the boundaries 0 and 1.

Parameters:

springBoundary: behaviour at the boundaries

public OnSwipe.Mode getAutoCompleteMode()

public void setAutoCompleteMode(OnSwipe.Mode autoCompleteMode)

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

public java.lang.String toString()

Source

/*
 * Copyright (C) 2022 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.core.dsl;

/**
 * Create automatic swipe handling object
 */
public class OnSwipe {

    private Drag mDragDirection = null;
    private Side mTouchAnchorSide = null;

    private String mTouchAnchorId = null;
    private String mLimitBoundsTo = null;
    private TouchUp mOnTouchUp = null;
    private String mRotationCenterId = null;
    private float mMaxVelocity = Float.NaN;
    private float mMaxAcceleration = Float.NaN;
    private float mDragScale = Float.NaN;

    private float mDragThreshold = Float.NaN;
    private float mSpringDamping = Float.NaN;
    private float mSpringMass = Float.NaN;
    private float mSpringStiffness = Float.NaN;
    private float mSpringStopThreshold = Float.NaN;
    private Boundary mSpringBoundary = null;
    private Mode mAutoCompleteMode = null;

    public OnSwipe() {
    }

    public OnSwipe(String anchor, Side side, Drag dragDirection) {
        mTouchAnchorId = anchor;
        mTouchAnchorSide = side;
        mDragDirection = dragDirection;
    }

    public enum Mode {
        VELOCITY,
        SPRING
    }

    public enum Boundary {
        OVERSHOOT,
        BOUNCE_START,
        BOUNCE_END,
        BOUNCE_BOTH,
    }


    public enum Drag {
        UP,
        DOWN,
        LEFT,
        RIGHT,
        START,
        END,
        CLOCKWISE,
        ANTICLOCKWISE
    }

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

    public enum Side {
        TOP,
        LEFT,
        RIGHT,
        BOTTOM,
        MIDDLE,
        START,
        END,
    }

    public enum TouchUp {
        AUTOCOMPLETE,
        TO_START,
        NEVER_COMPLETE_END,
        TO_END,
        STOP,
        DECELERATE,
        DECELERATE_COMPLETE,
        NEVER_COMPLETE_START
    }

    /**
     * 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 OnSwipe setTouchAnchorId(String id) {
        mTouchAnchorId = id;
        return this;
    }

    public String 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)
     */
    public OnSwipe setTouchAnchorSide(Side side) {
        mTouchAnchorSide = side;
        return this;
    }

    public Side getTouchAnchorSide() {
        return mTouchAnchorSide;
    }

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

    public Drag getDragDirection() {
        return mDragDirection;
    }

    /**
     * The maximum velocity (Change in progress per second) animation can achieve
     */
    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
     */
    public OnSwipe setMaxAcceleration(int maxAcceleration) {
        mMaxAcceleration = maxAcceleration;
        return this;
    }

    public float getMaxAcceleration() {
        return mMaxAcceleration;
    }


    /**
     * Normally 1 this can be tweaked to make the acceleration faster
     */
    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.
     */
    public OnSwipe setDragThreshold(int dragThreshold) {
        mDragThreshold = dragThreshold;
        return this;
    }

    public float getDragThreshold() {
        return mDragThreshold;
    }


    /**
     * 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
     */
    public OnSwipe setOnTouchUp(TouchUp mode) {
        mOnTouchUp = mode;
        return this;
    }

    public TouchUp getOnTouchUp() {
        return mOnTouchUp;
    }

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

    public String getLimitBoundsTo() {
        return mLimitBoundsTo;
    }

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

    public String 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
     *
     * @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
     */
    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
     *
     * @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
     */
    public OnSwipe setSpringStiffness(float springStiffness) {
        mSpringStiffness = springStiffness;
        return this;
    }

    /**
     * The threshold for spring motion to stop.
     */
    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 when to stop.
     */
    public OnSwipe setSpringStopThreshold(float springStopThreshold) {
        mSpringStopThreshold = springStopThreshold;
        return this;
    }

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

    /**
     * The behaviour at the boundaries 0 and 1.
     *
     * @param springBoundary behaviour at the boundaries
     */
    public OnSwipe setSpringBoundary(Boundary springBoundary) {
        mSpringBoundary = springBoundary;
        return this;
    }

    public Mode getAutoCompleteMode() {
        return mAutoCompleteMode;
    }


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

    @Override
    public String toString() {
        StringBuilder ret = new StringBuilder();
        ret.append("OnSwipe:{\n");
        if (mTouchAnchorId != null) {
            ret.append("anchor:'").append(mTouchAnchorId).append("',\n");
        }
        if (mDragDirection != null) {
            ret.append("direction:'").append(mDragDirection.toString().toLowerCase()).append(
                    "',\n");
        }
        if (mTouchAnchorSide != null) {
            ret.append("side:'").append(mTouchAnchorSide.toString().toLowerCase()).append("',\n");
        }
        if (!Float.isNaN(mDragScale)) {
            ret.append("scale:'").append(mDragScale).append("',\n");
        }
        if (!Float.isNaN(mDragThreshold)) {
            ret.append("threshold:'").append(mDragThreshold).append("',\n");
        }
        if (!Float.isNaN(mMaxVelocity)) {
            ret.append("maxVelocity:'").append(mMaxVelocity).append("',\n");
        }
        if (!Float.isNaN(mMaxAcceleration)) {
            ret.append("maxAccel:'").append(mMaxAcceleration).append("',\n");
        }
        if (mLimitBoundsTo != null) {
            ret.append("limitBounds:'").append(mLimitBoundsTo).append("',\n");
        }
        if (mAutoCompleteMode != null) {
            ret.append("mode:'").append(mAutoCompleteMode.toString().toLowerCase()).append("',\n");
        }
        if (mOnTouchUp != null) {
            ret.append("touchUp:'").append(mOnTouchUp.toString().toLowerCase()).append("',\n");
        }
        if (!Float.isNaN(mSpringMass)) {
            ret.append("springMass:'").append(mSpringMass).append("',\n");
        }

        if (!Float.isNaN(mSpringStiffness)) {
            ret.append("springStiffness:'").append(mSpringStiffness).append("',\n");
        }
        if (!Float.isNaN(mSpringDamping)) {
            ret.append("springDamping:'").append(mSpringDamping).append("',\n");
        }
        if (!Float.isNaN(mSpringStopThreshold)) {
            ret.append("stopThreshold:'").append(mSpringStopThreshold).append("',\n");
        }
        if (mSpringBoundary != null) {
            ret.append("springBoundary:'").append(mSpringBoundary).append("',\n");
        }
        if (mRotationCenterId != null) {
            ret.append("around:'").append(mRotationCenterId).append("',\n");
        }

        ret.append("},\n");

        return ret.toString();
    }
}