Skip to content

Commit

Permalink
PAINTROID_421_enlarge_canvas_import_tool
Browse files Browse the repository at this point in the history
showing dialog to enlarge when import is larger than canvas

- shown only if image is outside of canvas border
- maximum bitmap size still valid
  • Loading branch information
Julian Raphael Jautz committed Mar 20, 2024
1 parent b0a340d commit 266398a
Showing 1 changed file with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class ImportToolIntentTest {
private var initialWidth = 0
private var initialHeight = 0
private var maxBitmapSize = 0
private var initialBitmapHeight = 0
private var initialBitmapWidth = 0
private var maxWidth = 0
private lateinit var idlingResource: CountingIdlingResource
private lateinit var mainActivity: MainActivity
private lateinit var activityHelper: MainActivityHelper
Expand All @@ -106,7 +109,15 @@ class ImportToolIntentTest {
initialHeight = workingBitmap.height
perspective = mainActivity.perspective
workspace = mainActivity.workspace
maxWidth = maxBitmapSize / initialHeight
initialBitmapWidth = workspace.width
initialBitmapHeight = workspace.height
perspective.multiplyScale(.25f)
saveTestImage()
val imgGalleryResult = createImageGallerySetResultStub(mainActivity)
intending(hasAction(Intent.ACTION_GET_CONTENT)).respondWith(imgGalleryResult)
onView(withId(R.id.pocketpaint_dialog_import_gallery))
.perform(click())
}

@After
Expand All @@ -117,20 +128,11 @@ class ImportToolIntentTest {

@Test
fun testEnlargeCanvas() {
val maxWidth = maxBitmapSize / initialHeight
var initialBitmapWidth = workspace.width
var initialBitmapHeight = workspace.height
perspective.multiplyScale(.25f)
var dragFrom = perspective.getSurfacePointFromCanvasPoint(
PointF(initialBitmapWidth.toFloat(), initialBitmapHeight.toFloat()))
var dragTo = perspective.getSurfacePointFromCanvasPoint(
PointF(maxWidth + 10f, initialHeight.toFloat()))

val imgGalleryResult = createImageGallerySetResultStub(mainActivity)
intending(hasAction(Intent.ACTION_GET_CONTENT)).respondWith(imgGalleryResult)
onView(withId(R.id.pocketpaint_dialog_import_gallery))
.perform(click())

DrawingSurfaceInteraction.onDrawingSurfaceView()
.perform(UiInteractions.swipe(dragFrom, dragTo))
TopBarViewInteraction.onTopBarView().performClickCheckmark()
Expand Down Expand Up @@ -164,6 +166,24 @@ class ImportToolIntentTest {
initialBitmapHeight * initialBitmapWidth, workspace.height * workspace.width)
}

@Test
fun testEnlargeWhenSwitchingTool() {
val dragFrom = perspective.getSurfacePointFromCanvasPoint(
PointF(initialBitmapWidth.toFloat(), initialBitmapHeight.toFloat()))
val dragTo = perspective.getSurfacePointFromCanvasPoint(
PointF(maxWidth + 10f, initialHeight.toFloat()))

DrawingSurfaceInteraction.onDrawingSurfaceView()
.perform(UiInteractions.swipe(dragFrom, dragTo))
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.BRUSH)

onView(withText(R.string.dialog_import_image_enlarge_image)).check(
ViewAssertions.matches(ViewMatchers.isDisplayed()))
onView(withText(R.string.pocketpaint_enlarge)).perform(click())
Assert.assertTrue(initialBitmapHeight * initialBitmapWidth < workspace.height * workspace.width)
}

private fun saveTestImage() {
val bm = BitmapFactory.decodeResource(intentsTestRule.activity.resources, R.drawable.pocketpaint_logo)
val dir = intentsTestRule.activity.externalCacheDir
Expand Down

0 comments on commit 266398a

Please sign in to comment.