Skip to content

Instantly share code, notes, and snippets.

@tiwiz
Last active August 30, 2017 14:32
Show Gist options
  • Save tiwiz/79371360d2ceeba539283bbc079d7480 to your computer and use it in GitHub Desktop.
Save tiwiz/79371360d2ceeba539283bbc079d7480 to your computer and use it in GitHub Desktop.
RotationTestUtils.kt
@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