Skip to content

Commit

Permalink
Merge pull request Catrobat#1285 from foenabua/PAINTROID-554
Browse files Browse the repository at this point in the history
PAINTROID-554 Adjust Colorwheel in Pocket Paint
  • Loading branch information
SebastianGrief authored Jun 21, 2023
2 parents a044cad + 2a0be0a commit 612aaad
Show file tree
Hide file tree
Showing 6 changed files with 2,349 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ import org.hamcrest.TypeSafeMatcher
import org.junit.Assert

object UiMatcher {

private fun vectorToBitmap(vectorDrawable: VectorDrawable): Bitmap {
return Bitmap.createBitmap(
vectorDrawable.intrinsicWidth,
vectorDrawable.intrinsicHeight, Bitmap.Config.ARGB_8888
)
}

fun atPosition(position: Int, itemMatcher: Matcher<View>): BoundedMatcher<View?, RecyclerView> {
Preconditions.checkNotNull(itemMatcher)
return object : BoundedMatcher<View?, RecyclerView>(RecyclerView::class.java) {
Expand Down Expand Up @@ -249,13 +257,22 @@ object UiMatcher {
if (expectedDrawable == null || targetDrawable == null) {
return false
}
val expectedBitmap: Bitmap = (expectedDrawable as BitmapDrawable).bitmap
if (expectedDrawable::class != targetDrawable::class) {
return false
}

if (targetDrawable is BitmapDrawable) {
val bitmap: Bitmap = targetDrawable.bitmap
return bitmap.sameAs(expectedBitmap)
val targetBitmap: Bitmap = targetDrawable.bitmap
val expectedBitmap = (expectedDrawable as BitmapDrawable).bitmap
return targetBitmap.sameAs(expectedBitmap)
} else if (targetDrawable is VectorDrawable) {
val targetBitmap: Bitmap = vectorToBitmap(targetDrawable)
val expectedBitmap = vectorToBitmap(expectedDrawable as VectorDrawable)
return targetBitmap.sameAs(expectedBitmap)
} else if (targetDrawable is StateListDrawable) {
val bitmap: Bitmap = (targetDrawable.getCurrent() as BitmapDrawable).bitmap
return bitmap.sameAs(expectedBitmap)
val targetBitmap: Bitmap = (targetDrawable.getCurrent() as BitmapDrawable).bitmap
val expectedBitmap = (expectedDrawable as BitmapDrawable).bitmap
return targetBitmap.sameAs(expectedBitmap)
}
return false
}
Expand Down Expand Up @@ -373,12 +390,12 @@ object UiMatcher {
expectedBitmap = (expectedDrawable as BitmapDrawable).bitmap
return targetBitmap.sameAs(expectedBitmap)
} else if (targetDrawable is VectorDrawable || targetDrawable is VectorDrawableCompat) {
val targetBitmap: Bitmap = vectorToBitmap(expectedDrawable as VectorDrawable)
expectedBitmap = vectorToBitmap(expectedDrawable)
val targetBitmap: Bitmap = vectorToBitmap(targetDrawable as VectorDrawable)
expectedBitmap = vectorToBitmap(expectedDrawable as VectorDrawable)
return targetBitmap.sameAs(expectedBitmap)
} else if (targetDrawable is StateListDrawable) {
val targetBitmap: Bitmap = vectorToBitmap(expectedDrawable as VectorDrawable)
expectedBitmap = vectorToBitmap(expectedDrawable)
val targetBitmap: Bitmap = vectorToBitmap(targetDrawable.getCurrent() as VectorDrawable)
expectedBitmap = vectorToBitmap(expectedDrawable as VectorDrawable)
return targetBitmap.sameAs(expectedBitmap)
}
return false
Expand All @@ -393,13 +410,6 @@ object UiMatcher {
description.appendText("]")
}
}

private fun vectorToBitmap(vectorDrawable: VectorDrawable): Bitmap {
return Bitmap.createBitmap(
vectorDrawable.intrinsicWidth,
vectorDrawable.intrinsicHeight, Bitmap.Config.ARGB_8888
)
}
}
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 612aaad

Please sign in to comment.