Added in API level 1
Deprecated in API level 24

TouchUtils


open class TouchUtils
kotlin.Any
   ↳ android.test.TouchUtils

Reusable methods for generating touch events. These methods can be used with InstrumentationTestCase or ActivityInstrumentationTestCase2 to simulate user interaction with the application through a touch screen.

Summary

Public constructors

Public methods
open static Unit

Simulate touching the center of a view and releasing.

open static Unit
drag(test: ActivityInstrumentationTestCase<Activity!>!, fromX: Float, toX: Float, fromY: Float, toY: Float, stepCount: Int)

Simulate touching a specific location and dragging to a new location.

open static Unit
drag(test: InstrumentationTestCase!, fromX: Float, toX: Float, fromY: Float, toY: Float, stepCount: Int)

Simulate touching a specific location and dragging to a new location.

open static Unit

Simulate touching in the center of the screen and dragging one quarter of the way down

open static Unit

Simulate touching in the center of the screen and dragging one quarter of the way down

open static Unit

Simulate touching in the center of the screen and dragging one quarter of the way up

open static Unit

Simulate touching in the center of the screen and dragging one quarter of the way up

open static Int
dragViewBy(test: ActivityInstrumentationTestCase<Activity!>!, v: View!, gravity: Int, deltaX: Int, deltaY: Int)

Simulate touching a view and dragging it by the specified amount.

open static Int
dragViewBy(test: InstrumentationTestCase!, v: View!, gravity: Int, deltaX: Int, deltaY: Int)

Simulate touching a view and dragging it by the specified amount.

open static Int
dragViewTo(test: ActivityInstrumentationTestCase<Activity!>!, v: View!, gravity: Int, toX: Int, toY: Int)

Simulate touching a view and dragging it to a specified location.

open static Int
dragViewTo(test: InstrumentationTestCase!, v: View!, gravity: Int, toX: Int, toY: Int)

Simulate touching a view and dragging it to a specified location.

open static Unit

Simulate touching the center of a view and dragging to the bottom of the screen.

open static Unit

Simulate touching the center of a view and dragging to the bottom of the screen.

open static Unit

Simulate touching the center of a view and dragging to the bottom of the screen.

open static Unit
dragViewToBottom(test: InstrumentationTestCase!, activity: Activity!, v: View!, stepCount: Int)

Simulate touching the center of a view and dragging to the bottom of the screen.

open static Unit

Simulate touching the center of a view and dragging to the top of the screen.

open static Unit

Simulate touching the center of a view and dragging to the top of the screen.

open static Unit

Simulate touching the center of a view and dragging to the top of the screen.

open static Unit
dragViewToTop(test: InstrumentationTestCase!, v: View!, stepCount: Int)

Simulate touching the center of a view and dragging to the top of the screen.

open static Int
dragViewToX(test: ActivityInstrumentationTestCase<Activity!>!, v: View!, gravity: Int, toX: Int)

Simulate touching a view and dragging it to a specified location.

open static Int
dragViewToX(test: InstrumentationTestCase!, v: View!, gravity: Int, toX: Int)

Simulate touching a view and dragging it to a specified location.

open static Int
dragViewToY(test: ActivityInstrumentationTestCase<Activity!>!, v: View!, gravity: Int, toY: Int)

Simulate touching a view and dragging it to a specified location.

open static Int
dragViewToY(test: InstrumentationTestCase!, v: View!, gravity: Int, toY: Int)

Simulate touching a view and dragging it to a specified location.

open static Unit

Simulate touching the center of a view, holding until it is a long press, and then releasing.

open static Unit

Simulate touching the center of a view, holding until it is a long press, and then releasing.

open static Unit

Scroll a ViewGroup to the bottom by repeatedly calling dragQuarterScreenUp(android.test.InstrumentationTestCase,android.app.Activity)

open static Unit

Scroll a ViewGroup to the bottom by repeatedly calling dragQuarterScreenUp(android.test.InstrumentationTestCase,android.app.Activity)

open static Unit

Scroll a ViewGroup to the top by repeatedly calling dragQuarterScreenDown(android.test.InstrumentationTestCase,android.app.Activity)

open static Unit

Scroll a ViewGroup to the top by repeatedly calling dragQuarterScreenDown(android.test.InstrumentationTestCase,android.app.Activity)

open static Unit

Simulate touching the center of a view and releasing quickly (before the tap timeout).

open static Unit

Simulate touching the center of a view and cancelling (so no onClick should fire, etc).

Public constructors

TouchUtils

TouchUtils()

Public methods

clickView

Added in API level 1
open static fun clickView(
    test: InstrumentationTestCase!,
    v: View!
): Unit

Deprecated: Deprecated in Java.

Simulate touching the center of a view and releasing.

Parameters
test InstrumentationTestCase!: The test case that is being run
v View!: The view that should be clicked

drag

Added in API level 1
Deprecated in API level 15
open static fun drag(
    test: ActivityInstrumentationTestCase<Activity!>!,
    fromX: Float,
    toX: Float,
    fromY: Float,
    toY: Float,
    stepCount: Int
): Unit

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Simulate touching a specific location and dragging to a new location.

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run
fromX Float: X coordinate of the initial touch, in screen coordinates
toX Float: Xcoordinate of the drag destination, in screen coordinates
fromY Float: X coordinate of the initial touch, in screen coordinates
toY Float: Y coordinate of the drag destination, in screen coordinates
stepCount Int: How many move steps to include in the drag

drag

Added in API level 3
Deprecated in API level 24
open static fun drag(
    test: InstrumentationTestCase!,
    fromX: Float,
    toX: Float,
    fromY: Float,
    toY: Float,
    stepCount: Int
): Unit

Deprecated: Deprecated in Java.

Simulate touching a specific location and dragging to a new location.

Parameters
test InstrumentationTestCase!: The test case that is being run
fromX Float: X coordinate of the initial touch, in screen coordinates
toX Float: Xcoordinate of the drag destination, in screen coordinates
fromY Float: X coordinate of the initial touch, in screen coordinates
toY Float: Y coordinate of the drag destination, in screen coordinates
stepCount Int: How many move steps to include in the drag

dragQuarterScreenDown

Added in API level 1
Deprecated in API level 15
open static fun dragQuarterScreenDown(test: ActivityInstrumentationTestCase<Activity!>!): Unit

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Simulate touching in the center of the screen and dragging one quarter of the way down

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run

dragQuarterScreenDown

Added in API level 3
Deprecated in API level 24
open static fun dragQuarterScreenDown(
    test: InstrumentationTestCase!,
    activity: Activity!
): Unit

Deprecated: Deprecated in Java.

Simulate touching in the center of the screen and dragging one quarter of the way down

Parameters
test InstrumentationTestCase!: The test case that is being run
activity Activity!: The activity that is in the foreground of the test case

dragQuarterScreenUp

Added in API level 1
Deprecated in API level 15
open static fun dragQuarterScreenUp(test: ActivityInstrumentationTestCase<Activity!>!): Unit

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Simulate touching in the center of the screen and dragging one quarter of the way up

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run

dragQuarterScreenUp

Added in API level 3
Deprecated in API level 24
open static fun dragQuarterScreenUp(
    test: InstrumentationTestCase!,
    activity: Activity!
): Unit

Deprecated: Deprecated in Java.

Simulate touching in the center of the screen and dragging one quarter of the way up

Parameters
test InstrumentationTestCase!: The test case that is being run
activity Activity!: The activity that is in the foreground of the test case

dragViewBy

Added in API level 1
Deprecated in API level 15
open static fun dragViewBy(
    test: ActivityInstrumentationTestCase<Activity!>!,
    v: View!,
    gravity: Int,
    deltaX: Int,
    deltaY: Int
): Int

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Simulate touching a view and dragging it by the specified amount.

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run
v View!: The view that should be dragged
gravity Int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
deltaX Int: Amount to drag horizontally in pixels
deltaY Int: Amount to drag vertically in pixels
Return
Int distance in pixels covered by the drag

dragViewBy

Added in API level 3
Deprecated in API level 15
open static fun dragViewBy(
    test: InstrumentationTestCase!,
    v: View!,
    gravity: Int,
    deltaX: Int,
    deltaY: Int
): Int

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Simulate touching a view and dragging it by the specified amount.

Parameters
test InstrumentationTestCase!: The test case that is being run
v View!: The view that should be dragged
gravity Int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
deltaX Int: Amount to drag horizontally in pixels
deltaY Int: Amount to drag vertically in pixels
Return
Int distance in pixels covered by the drag

dragViewTo

Added in API level 1
Deprecated in API level 15
open static fun dragViewTo(
    test: ActivityInstrumentationTestCase<Activity!>!,
    v: View!,
    gravity: Int,
    toX: Int,
    toY: Int
): Int

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Simulate touching a view and dragging it to a specified location.

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run
v View!: The view that should be dragged
gravity Int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
toX Int: Final location of the view after dragging
toY Int: Final location of the view after dragging
Return
Int distance in pixels covered by the drag

dragViewTo

Added in API level 3
Deprecated in API level 24
open static fun dragViewTo(
    test: InstrumentationTestCase!,
    v: View!,
    gravity: Int,
    toX: Int,
    toY: Int
): Int

Deprecated: Deprecated in Java.

Simulate touching a view and dragging it to a specified location.

Parameters
test InstrumentationTestCase!: The test case that is being run
v View!: The view that should be dragged
gravity Int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
toX Int: Final location of the view after dragging
toY Int: Final location of the view after dragging
Return
Int distance in pixels covered by the drag

dragViewToBottom

Added in API level 1
Deprecated in API level 15
open static fun dragViewToBottom(
    test: ActivityInstrumentationTestCase<Activity!>!,
    v: View!
): Unit

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Simulate touching the center of a view and dragging to the bottom of the screen.

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run
v View!: The view that should be dragged

dragViewToBottom

Added in API level 3
Deprecated in API level 24
open static fun dragViewToBottom(
    test: InstrumentationTestCase!,
    activity: Activity!,
    v: View!
): Unit

Deprecated: Deprecated in Java.

Simulate touching the center of a view and dragging to the bottom of the screen.

Parameters
test InstrumentationTestCase!: The test case that is being run
activity Activity!: The activity that is in the foreground of the test case
v View!: The view that should be dragged

dragViewToBottom

Added in API level 1
Deprecated in API level 15
open static fun dragViewToBottom(
    test: ActivityInstrumentationTestCase<Activity!>!,
    v: View!,
    stepCount: Int
): Unit

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Simulate touching the center of a view and dragging to the bottom of the screen.

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run
v View!: The view that should be dragged
stepCount Int: How many move steps to include in the drag

dragViewToBottom

Added in API level 3
Deprecated in API level 24
open static fun dragViewToBottom(
    test: InstrumentationTestCase!,
    activity: Activity!,
    v: View!,
    stepCount: Int
): Unit

Deprecated: Deprecated in Java.

Simulate touching the center of a view and dragging to the bottom of the screen.

Parameters
test InstrumentationTestCase!: The test case that is being run
activity Activity!: The activity that is in the foreground of the test case
v View!: The view that should be dragged
stepCount Int: How many move steps to include in the drag

dragViewToTop

Added in API level 1
Deprecated in API level 15
open static fun dragViewToTop(
    test: ActivityInstrumentationTestCase<Activity!>!,
    v: View!
): Unit

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Simulate touching the center of a view and dragging to the top of the screen.

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run
v View!: The view that should be dragged

dragViewToTop

Added in API level 1
Deprecated in API level 15
open static fun dragViewToTop(
    test: ActivityInstrumentationTestCase<Activity!>!,
    v: View!,
    stepCount: Int
): Unit

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Simulate touching the center of a view and dragging to the top of the screen.

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run
v View!: The view that should be dragged
stepCount Int: How many move steps to include in the drag

dragViewToTop

Added in API level 3
Deprecated in API level 24
open static fun dragViewToTop(
    test: InstrumentationTestCase!,
    v: View!
): Unit

Deprecated: Deprecated in Java.

Simulate touching the center of a view and dragging to the top of the screen.

Parameters
test InstrumentationTestCase!: The test case that is being run
v View!: The view that should be dragged

dragViewToTop

Added in API level 3
Deprecated in API level 24
open static fun dragViewToTop(
    test: InstrumentationTestCase!,
    v: View!,
    stepCount: Int
): Unit

Deprecated: Deprecated in Java.

Simulate touching the center of a view and dragging to the top of the screen.

Parameters
test InstrumentationTestCase!: The test case that is being run
v View!: The view that should be dragged
stepCount Int: How many move steps to include in the drag

dragViewToX

Added in API level 1
Deprecated in API level 15
open static fun dragViewToX(
    test: ActivityInstrumentationTestCase<Activity!>!,
    v: View!,
    gravity: Int,
    toX: Int
): Int

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Simulate touching a view and dragging it to a specified location. Only moves horizontally.

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run
v View!: The view that should be dragged
gravity Int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
toX Int: Final location of the view after dragging
Return
Int distance in pixels covered by the drag

dragViewToX

Added in API level 3
Deprecated in API level 24
open static fun dragViewToX(
    test: InstrumentationTestCase!,
    v: View!,
    gravity: Int,
    toX: Int
): Int

Deprecated: Deprecated in Java.

Simulate touching a view and dragging it to a specified location. Only moves horizontally.

Parameters
test InstrumentationTestCase!: The test case that is being run
v View!: The view that should be dragged
gravity Int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
toX Int: Final location of the view after dragging
Return
Int distance in pixels covered by the drag

dragViewToY

Added in API level 1
Deprecated in API level 15
open static fun dragViewToY(
    test: ActivityInstrumentationTestCase<Activity!>!,
    v: View!,
    gravity: Int,
    toY: Int
): Int

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Simulate touching a view and dragging it to a specified location. Only moves vertically.

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run
v View!: The view that should be dragged
gravity Int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
toY Int: Final location of the view after dragging
Return
Int distance in pixels covered by the drag

dragViewToY

Added in API level 3
Deprecated in API level 24
open static fun dragViewToY(
    test: InstrumentationTestCase!,
    v: View!,
    gravity: Int,
    toY: Int
): Int

Deprecated: Deprecated in Java.

Simulate touching a view and dragging it to a specified location. Only moves vertically.

Parameters
test InstrumentationTestCase!: The test case that is being run
v View!: The view that should be dragged
gravity Int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
toY Int: Final location of the view after dragging
Return
Int distance in pixels covered by the drag

longClickView

Added in API level 1
Deprecated in API level 15
open static fun longClickView(
    test: ActivityInstrumentationTestCase<Activity!>!,
    v: View!
): Unit

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Simulate touching the center of a view, holding until it is a long press, and then releasing.

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run
v View!: The view that should be clicked

longClickView

Added in API level 3
Deprecated in API level 24
open static fun longClickView(
    test: InstrumentationTestCase!,
    v: View!
): Unit

Deprecated: Deprecated in Java.

Simulate touching the center of a view, holding until it is a long press, and then releasing.

Parameters
test InstrumentationTestCase!: The test case that is being run
v View!: The view that should be clicked

scrollToBottom

Added in API level 1
Deprecated in API level 15
open static fun scrollToBottom(
    test: ActivityInstrumentationTestCase<Activity!>!,
    v: ViewGroup!
): Unit

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Scroll a ViewGroup to the bottom by repeatedly calling dragQuarterScreenUp(android.test.InstrumentationTestCase,android.app.Activity)

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run
v ViewGroup!: The ViewGroup that should be dragged

scrollToBottom

Added in API level 3
Deprecated in API level 24
open static fun scrollToBottom(
    test: InstrumentationTestCase!,
    activity: Activity!,
    v: ViewGroup!
): Unit

Deprecated: Deprecated in Java.

Scroll a ViewGroup to the bottom by repeatedly calling dragQuarterScreenUp(android.test.InstrumentationTestCase,android.app.Activity)

Parameters
test InstrumentationTestCase!: The test case that is being run
activity Activity!: The activity that is in the foreground of the test case
v ViewGroup!: The ViewGroup that should be dragged

scrollToTop

Added in API level 1
Deprecated in API level 15
open static fun scrollToTop(
    test: ActivityInstrumentationTestCase<Activity!>!,
    v: ViewGroup!
): Unit

Deprecated: android.test.ActivityInstrumentationTestCase is deprecated in favor of android.test.ActivityInstrumentationTestCase2, which provides more options for configuring the Activity under test

Scroll a ViewGroup to the top by repeatedly calling dragQuarterScreenDown(android.test.InstrumentationTestCase,android.app.Activity)

Parameters
test ActivityInstrumentationTestCase<Activity!>!: The test case that is being run
v ViewGroup!: The ViewGroup that should be dragged

scrollToTop

Added in API level 3
Deprecated in API level 24
open static fun scrollToTop(
    test: InstrumentationTestCase!,
    activity: Activity!,
    v: ViewGroup!
): Unit

Deprecated: Deprecated in Java.

Scroll a ViewGroup to the top by repeatedly calling dragQuarterScreenDown(android.test.InstrumentationTestCase,android.app.Activity)

Parameters
test InstrumentationTestCase!: The test case that is being run
activity Activity!: The activity that is in the foreground of the test case
v ViewGroup!: The ViewGroup that should be dragged

tapView

Added in API level 1
open static fun tapView(
    test: InstrumentationTestCase!,
    v: View!
): Unit

Deprecated: Deprecated in Java.

Simulate touching the center of a view and releasing quickly (before the tap timeout).

Parameters
test InstrumentationTestCase!: The test case that is being run
v View!: The view that should be clicked

touchAndCancelView

Added in API level 1
open static fun touchAndCancelView(
    test: InstrumentationTestCase!,
    v: View!
): Unit

Deprecated: Deprecated in Java.

Simulate touching the center of a view and cancelling (so no onClick should fire, etc).

Parameters
test InstrumentationTestCase!: The test case that is being run
v View!: The view that should be clicked