Last active
August 30, 2017 14:32
-
-
Save tiwiz/79371360d2ceeba539283bbc079d7480 to your computer and use it in GitHub Desktop.
RotationTestUtils.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@file:JvmName("RotationTestUtils") | |
package com.your.package. | |
import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE | |
import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT | |
import android.content.res.Configuration | |
import android.content.res.Configuration.ORIENTATION_PORTRAIT | |
import android.support.test.InstrumentationRegistry | |
import android.support.test.rule.ActivityTestRule | |
fun ActivityTestRule<*>.rotateScreen() = | |
InstrumentationRegistry.getTargetContext() | |
.resources.configuration.run { | |
activity.requestedOrientation = rotate() | |
} | |
private fun Configuration.rotate() = | |
if(orientation == ORIENTATION_PORTRAIT) SCREEN_ORIENTATION_LANDSCAPE else SCREEN_ORIENTATION_PORTRAIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment