Skip to content

Instantly share code, notes, and snippets.

@plnice
Last active September 8, 2019 18:31
Show Gist options
  • Save plnice/ad9b28a90c743379e1d643e6c56f8d9d to your computer and use it in GitHub Desktop.
Save plnice/ad9b28a90c743379e1d643e6c56f8d9d to your computer and use it in GitHub Desktop.
fun withDrawable(@DrawableRes id: Int, @ColorRes tint: Int? = null, tintMode: PorterDuff.Mode = SRC_IN) = object : TypeSafeMatcher<View>() {
override fun describeTo(description: Description) {
description.appendText("ImageView with drawable same as drawable with id $id")
tint?.let { description.appendText(", tint color id: $tint, mode: $tintMode") }
}
override fun matchesSafely(view: View): Boolean {
val context = view.context
val tintColor = tint?.toColor(context)
val expectedBitmap = context.getDrawable(id).tinted(tintColor, tintMode).toBitmap()
return view is ImageView && view.drawable.toBitmap().sameAs(expectedBitmap)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment