Added in API level 34

BackEvent


class BackEvent
kotlin.Any
   ↳ android.window.BackEvent

Object used to report back gesture progress. Holds information about the touch event, swipe direction and the animation progress that predictive back animations should seek to.

Summary

Constants
static Int

Indicates that the edge swipe starts from the left edge of the screen

static Int

Indicates that the back event was not triggered by an edge swipe back gesture.

static Int

Indicates that the edge swipe starts from the right edge of the screen

Public constructors
BackEvent(touchX: Float, touchY: Float, progress: Float, swipeEdge: Int)

Creates a new BackEvent instance with a frame time of 0.

BackEvent(touchX: Float, touchY: Float, progress: Float, swipeEdge: Int, frameTimeMillis: Long)

Creates a new BackEvent instance.

Public methods
Boolean
equals(other: Any?)

Indicates whether some other object is "equal to" this one.

Long

Returns the frameTime of the BackEvent in milliseconds.

Float

Returns a value between 0 and 1 on how far along the back gesture is.

Int

Returns the screen edge that the swipe starts from.

Float

Returns the absolute X location of the touch point, or NaN if the event is from a button press.

Float

Returns the absolute Y location of the touch point, or NaN if the event is from a button press.

String

Returns a string representation of the object.

Constants

EDGE_LEFT

Added in API level 34
static val EDGE_LEFT: Int

Indicates that the edge swipe starts from the left edge of the screen

Value: 0

EDGE_NONE

Added in API level 36
static val EDGE_NONE: Int

Indicates that the back event was not triggered by an edge swipe back gesture. This applies to cases like using the back button in 3-button navigation or pressing a hardware back button.

Value: 2

EDGE_RIGHT

Added in API level 34
static val EDGE_RIGHT: Int

Indicates that the edge swipe starts from the right edge of the screen

Value: 1

Public constructors

BackEvent

Added in API level 34
BackEvent(
    touchX: Float,
    touchY: Float,
    progress: Float,
    swipeEdge: Int)

Creates a new BackEvent instance with a frame time of 0.

Parameters
touchX Float: Absolute X location of the touch point of this event.
touchY Float: Absolute Y location of the touch point of this event.
progress Float: Value between 0 and 1 on how far along the back gesture is.
swipeEdge Int: Indicates which edge the swipe starts from.
Value is one of the following:

BackEvent

Added in API level 36
BackEvent(
    touchX: Float,
    touchY: Float,
    progress: Float,
    swipeEdge: Int,
    frameTimeMillis: Long)

Creates a new BackEvent instance.

Parameters
touchX Float: Absolute X location of the touch point of this event.
touchY Float: Absolute Y location of the touch point of this event.
progress Float: Value between 0 and 1 on how far along the back gesture is.
swipeEdge Int: Indicates which edge the swipe starts from.
Value is one of the following:
frameTimeMillis Long: frame time of the back event.

Public methods

equals

Added in API level 34
fun equals(other: Any?): Boolean

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj the reference object with which to compare.
Return
Boolean true if this object is the same as the obj argument; false otherwise.

getFrameTimeMillis

Added in API level 36
fun getFrameTimeMillis(): Long

Returns the frameTime of the BackEvent in milliseconds. Useful for calculating velocity.

getProgress

Added in API level 34
fun getProgress(): Float

Returns a value between 0 and 1 on how far along the back gesture is. This value is driven by the horizontal location of the touch point, and should be used as the fraction to seek the predictive back animation with. Specifically,

  1. The progress is 0 when the touch is at the starting edge of the screen (left or right), and animation should seek to its start state.
  2. The progress is approximately 1 when the touch is at the opposite side of the screen, and animation should seek to its end state. Exact end value may vary depending on screen size.
  • After the gesture finishes in cancel state, this method keeps getting invoked until the progress value animates back to 0. In-between locations are linearly interpolated based on horizontal distance from the starting edge and smooth clamped to 1 when the distance exceeds a system-wide threshold.
  • Return
    Float Value is between 0.0f and 1.0f inclusive

    getSwipeEdge

    Added in API level 34
    fun getSwipeEdge(): Int

    Returns the screen edge that the swipe starts from.

    Return
    Int Value is one of the following:

    getTouchX

    Added in API level 34
    fun getTouchX(): Float

    Returns the absolute X location of the touch point, or NaN if the event is from a button press.

    getTouchY

    Added in API level 34
    fun getTouchY(): Float

    Returns the absolute Y location of the touch point, or NaN if the event is from a button press.

    toString

    Added in API level 34
    fun toString(): String

    Returns a string representation of the object.

    Return
    String a string representation of the object.