@@ -17,7 +17,16 @@ package androidx.test.espresso.device
1717
1818import androidx.test.annotation.ExperimentalTestApi
1919import androidx.test.espresso.device.action.DeviceAction
20+ import androidx.test.espresso.device.action.ScreenOrientation
21+ import androidx.test.espresso.device.action.setBookMode as getSetBookModeDeviceAction
22+ import androidx.test.espresso.device.action.setClosedMode as getSetClosedModeDeviceAction
23+ import androidx.test.espresso.device.action.setDisplaySize as getSetDisplaySizeDeviceAction
24+ import androidx.test.espresso.device.action.setFlatMode as getSetFlatModeDeviceAction
25+ import androidx.test.espresso.device.action.setScreenOrientation as getSetScreenOrientationDeviceAction
26+ import androidx.test.espresso.device.action.setTabletopMode as getSetTabletopModeDeviceAction
2027import androidx.test.espresso.device.context.ActionContext
28+ import androidx.test.espresso.device.sizeclass.HeightSizeClass
29+ import androidx.test.espresso.device.sizeclass.WidthSizeClass
2130import androidx.test.internal.util.Checks.checkNotMainThread
2231import androidx.test.platform.device.DeviceController
2332import javax.inject.Inject
@@ -45,4 +54,97 @@ constructor(private val context: ActionContext, private val deviceController: De
4554 action.perform(context, deviceController)
4655 return this
4756 }
57+
58+ companion object {
59+ /* *
60+ * Set device screen to be folded with the hinge in the horizontal position. For details on
61+ * foldable postures, see
62+ * https://developer.android.com/guide/topics/large-screens/learn-about-foldables#foldable_postures
63+ *
64+ * This action is for foldable devices only. Currently only supported for tests run on Android
65+ * Emulators.
66+ *
67+ * @throws UnsupportedDeviceOperationException if used on a real device.
68+ * @throws DeviceControllerOperationException when called on a non-foldable Emulator.
69+ */
70+ @ExperimentalTestApi
71+ fun DeviceInteraction.setTabletopMode (): DeviceInteraction {
72+ perform(getSetTabletopModeDeviceAction())
73+ return this
74+ }
75+
76+ /* *
77+ * Set device screen to be folded with the hinge in the vertical position. For details on
78+ * foldable postures, see
79+ * https://developer.android.com/guide/topics/large-screens/learn-about-foldables#foldable_postures
80+ *
81+ * This action is for foldable devices only. Currently only supported for tests run on Android
82+ * Emulators.
83+ *
84+ * @throws UnsupportedDeviceOperationException if used on a real device.
85+ * @throws DeviceControllerOperationException when called on a non-foldable Emulator.
86+ */
87+ @ExperimentalTestApi
88+ fun DeviceInteraction.setBookMode (): DeviceInteraction {
89+ perform(getSetBookModeDeviceAction())
90+ return this
91+ }
92+
93+ /* *
94+ * Set device screen to be completely flat, like a tablet. For details on foldable postures, see
95+ * https://developer.android.com/guide/topics/large-screens/learn-about-foldables#foldable_postures
96+ *
97+ * This action is for foldable devices only. Currently only supported for tests run on Android
98+ * Emulators.
99+ *
100+ * @throws UnsupportedDeviceOperationException if used on a real device.
101+ * @throws DeviceControllerOperationException when called on a non-foldable Emulator.
102+ */
103+ @ExperimentalTestApi
104+ fun DeviceInteraction.setFlatMode (): DeviceInteraction {
105+ perform(getSetFlatModeDeviceAction())
106+ return this
107+ }
108+
109+ /* *
110+ * Set device screen to be closed.
111+ *
112+ * This action is for foldable devices only. Currently only supported for tests run on Android
113+ * Emulators.
114+ *
115+ * @throws UnsupportedDeviceOperationException if used on a real device.
116+ * @throws DeviceControllerOperationException when called on a non-foldable Emulator.
117+ */
118+ @ExperimentalTestApi
119+ fun DeviceInteraction.setClosedMode (): DeviceInteraction {
120+ perform(getSetClosedModeDeviceAction())
121+ return this
122+ }
123+
124+ /* *
125+ * Set device's screen orientation.
126+ *
127+ * @param orientation the orientation to set the device to (portait or landscape)
128+ */
129+ @ExperimentalTestApi
130+ fun DeviceInteraction.setScreenOrientation (orientation : ScreenOrientation ): DeviceInteraction {
131+ perform(getSetScreenOrientationDeviceAction(orientation))
132+ return this
133+ }
134+
135+ /* *
136+ * Set device's display size.
137+ *
138+ * @param widthSizeClass the width to set the device display to
139+ * @param heightSizeClass the height to set the device display to
140+ */
141+ @ExperimentalTestApi
142+ fun DeviceInteraction.setDisplaySize (
143+ widthSizeClass : WidthSizeClass ,
144+ heightSizeClass : HeightSizeClass
145+ ): DeviceInteraction {
146+ perform(getSetDisplaySizeDeviceAction(widthSizeClass, heightSizeClass))
147+ return this
148+ }
149+ }
48150}
0 commit comments