Last active
September 8, 2019 18:31
-
-
Save plnice/ad9b28a90c743379e1d643e6c56f8d9d to your computer and use it in GitHub Desktop.
This file contains 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
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