Skip to content

Commit

Permalink
PAINTROID-624 Added default values for consistancy
Browse files Browse the repository at this point in the history
  • Loading branch information
exland committed Sep 1, 2023
2 parents 66ceb29 + bd080c0 commit ebb7a6f
Show file tree
Hide file tree
Showing 16 changed files with 333 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package org.catrobat.paintroid.test.espresso.tools

/*
* Paintroid: An image manipulation application for Android.
* Copyright (C) 2010-2023 The Catrobat Team
Expand All @@ -17,16 +19,29 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.catrobat.paintroid.test.espresso.tools

import android.graphics.Color
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.catrobat.paintroid.MainActivity
import org.catrobat.paintroid.R
import org.catrobat.paintroid.test.espresso.util.BitmapLocationProvider
import org.catrobat.paintroid.test.espresso.util.DrawingSurfaceLocationProvider
import org.catrobat.paintroid.test.espresso.util.UiInteractions
import org.catrobat.paintroid.test.espresso.util.UiInteractions.swipeAccurate
import org.catrobat.paintroid.test.espresso.util.UiMatcher
import org.catrobat.paintroid.test.espresso.util.wrappers.ColorPickerViewInteraction.Companion.onColorPickerView
import org.catrobat.paintroid.test.espresso.util.wrappers.DrawingSurfaceInteraction
import org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction
import org.catrobat.paintroid.test.espresso.util.wrappers.ToolPropertiesInteraction
import org.catrobat.paintroid.test.utils.ScreenshotOnFailRule
import org.catrobat.paintroid.tools.ToolReference
import org.catrobat.paintroid.tools.ToolType
import org.hamcrest.Matchers
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
Expand All @@ -38,10 +53,14 @@ import org.junit.runner.RunWith
class BrushToolIntegrationTest {

private lateinit var activity: MainActivity
private var toolReference: ToolReference? = null

@get:Rule
var activityScenarioRule: ActivityScenarioRule<MainActivity> = ActivityScenarioRule(MainActivity::class.java)

@get:Rule
var screenshotOnFailRule = ScreenshotOnFailRule()

private fun getActivity(): MainActivity {
lateinit var activity: MainActivity
activityScenarioRule.scenario.onActivity {
Expand All @@ -53,6 +72,8 @@ class BrushToolIntegrationTest {
@Before
fun setUp() {
activity = getActivity()
toolReference = activity.toolReference
ToolBarViewInteraction.onToolBarView().performSelectTool(ToolType.BRUSH)
}

@Test
Expand All @@ -64,4 +85,97 @@ class BrushToolIntegrationTest {
val updatedCommandCount = commandManager.getUndoCommandCount()
assertEquals(previousCommandCount + 1, updatedCommandCount)
}

@Test
fun testBrushToolColor() {
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.BRUSH)
DrawingSurfaceInteraction.onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.MIDDLE))
DrawingSurfaceInteraction.onDrawingSurfaceView()
.checkPixelColor(Color.BLACK, BitmapLocationProvider.MIDDLE)
}

@Test
fun testBrushToolTransparentColor() {
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.BRUSH)
onColorPickerView()
.performOpenColorPicker()
Espresso.onView(
Matchers.allOf(
withId(R.id.color_picker_tab_icon),
UiMatcher.withBackground(R.drawable.ic_color_picker_tab_preset)
)
).perform(ViewActions.click())
Espresso.onView(withId(R.id.color_alpha_slider)).perform(
ViewActions.scrollTo(),
UiInteractions.touchCenterMiddle()
)
Espresso.onView(
Matchers.allOf(
withId(R.id.color_picker_tab_icon),
UiMatcher.withBackground(R.drawable.ic_color_picker_tab_rgba)
)
).perform(ViewActions.click())
onColorPickerView()
.onPositiveButton()
.perform(ViewActions.click())
DrawingSurfaceInteraction.onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.MIDDLE))

val selectedColor = toolReference?.tool?.drawPaint!!.color
DrawingSurfaceInteraction.onDrawingSurfaceView()
.checkPixelColor(selectedColor, BitmapLocationProvider.MIDDLE)
}

@Test
fun testBrushToolWithHandleMoveColor() {
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.BRUSH)
ToolPropertiesInteraction.onToolProperties()
.setColor(Color.BLACK)
DrawingSurfaceInteraction.onDrawingSurfaceView()
.perform(UiInteractions.swipe(DrawingSurfaceLocationProvider.MIDDLE, DrawingSurfaceLocationProvider.BOTTOM_MIDDLE))
DrawingSurfaceInteraction.onDrawingSurfaceView()
.checkPixelColor(Color.BLACK, BitmapLocationProvider.MIDDLE)
}

@Test
fun testBrushToolWithHandleMoveTransparentColor() {
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.BRUSH)
onColorPickerView()
.performOpenColorPicker()
Espresso.onView(
Matchers.allOf(
withId(R.id.color_picker_tab_icon),
UiMatcher.withBackground(R.drawable.ic_color_picker_tab_preset)
)
).perform(ViewActions.click())
Espresso.onView(withId(R.id.color_alpha_slider)).perform(
ViewActions.scrollTo(),
UiInteractions.touchCenterMiddle()
)
Espresso.onView(
Matchers.allOf(
withId(R.id.color_picker_tab_icon),
UiMatcher.withBackground(R.drawable.ic_color_picker_tab_rgba)
)
).perform(ViewActions.click())
onColorPickerView()
.onPositiveButton()
.perform(ViewActions.click())
DrawingSurfaceInteraction.onDrawingSurfaceView()
.perform(
UiInteractions.swipe(
DrawingSurfaceLocationProvider.MIDDLE,
DrawingSurfaceLocationProvider.BOTTOM_MIDDLE
)
)

val selectedColor = toolReference?.tool?.drawPaint!!.color
DrawingSurfaceInteraction.onDrawingSurfaceView()
.checkPixelColor(selectedColor, BitmapLocationProvider.MIDDLE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
*/
package org.catrobat.paintroid.test.espresso.tools

import android.graphics.Color
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
Expand All @@ -27,18 +30,28 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import org.catrobat.paintroid.MainActivity
import org.catrobat.paintroid.R
import org.catrobat.paintroid.test.espresso.util.BitmapLocationProvider
import org.catrobat.paintroid.test.espresso.util.DrawingSurfaceLocationProvider
import org.catrobat.paintroid.test.espresso.util.UiInteractions
import org.catrobat.paintroid.test.espresso.util.UiMatcher
import org.catrobat.paintroid.test.espresso.util.UiMatcher.withProgress
import org.catrobat.paintroid.test.espresso.util.wrappers.ColorPickerViewInteraction.Companion.onColorPickerView
import org.catrobat.paintroid.test.espresso.util.wrappers.DrawingSurfaceInteraction.Companion.onDrawingSurfaceView
import org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction
import org.catrobat.paintroid.test.espresso.util.wrappers.ToolPropertiesInteraction.Companion.onToolProperties
import org.catrobat.paintroid.test.utils.ScreenshotOnFailRule
import org.catrobat.paintroid.tools.ToolReference
import org.catrobat.paintroid.tools.ToolType
import org.catrobat.paintroid.ui.tools.MIN_RADIUS
import org.hamcrest.Matchers.allOf
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class SprayToolIntegrationTest {
private var toolReference: ToolReference? = null

@get:Rule
var launchActivityRule = ActivityTestRule(MainActivity::class.java)
Expand All @@ -48,6 +61,7 @@ class SprayToolIntegrationTest {

@Before
fun setUp() {
toolReference = launchActivityRule.activity.toolReference
ToolBarViewInteraction.onToolBarView().performSelectTool(ToolType.SPRAY)
}

Expand All @@ -63,6 +77,98 @@ class SprayToolIntegrationTest {
}

@Test
fun testSprayToolColor() {
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.SPRAY)
onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.MIDDLE))
onDrawingSurfaceView()
.checkPixelColor(Color.BLACK, BitmapLocationProvider.MIDDLE)
}

@Test
fun testSprayToolTransparentColor() {
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.SPRAY)
onColorPickerView()
.performOpenColorPicker()
onView(
allOf(
withId(R.id.color_picker_tab_icon),
UiMatcher.withBackground(R.drawable.ic_color_picker_tab_preset)
)
).perform(click())
onView(withId(R.id.color_alpha_slider)).perform(
ViewActions.scrollTo(),
UiInteractions.touchCenterMiddle()
)
onView(
allOf(
withId(R.id.color_picker_tab_icon),
UiMatcher.withBackground(R.drawable.ic_color_picker_tab_rgba)
)
).perform(click())
onColorPickerView()
.onPositiveButton()
.perform(click())
onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.MIDDLE))

val selectedColor = toolReference?.tool?.drawPaint!!.color
onDrawingSurfaceView()
.checkPixelColor(selectedColor, BitmapLocationProvider.MIDDLE)
}

@Test
fun testSprayToolWithHandleMoveColor() {
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.SPRAY)
onToolProperties()
.setColor(Color.BLACK)
onDrawingSurfaceView()
.perform(UiInteractions.swipe(DrawingSurfaceLocationProvider.MIDDLE, DrawingSurfaceLocationProvider.BOTTOM_MIDDLE))
onDrawingSurfaceView()
.checkPixelColor(Color.BLACK, BitmapLocationProvider.MIDDLE)
}

@Test
fun testSprayToolWithHandleMoveTransparentColor() {
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.SPRAY)
onColorPickerView()
.performOpenColorPicker()
onView(
allOf(
withId(R.id.color_picker_tab_icon),
UiMatcher.withBackground(R.drawable.ic_color_picker_tab_preset)
)
).perform(click())
onView(withId(R.id.color_alpha_slider)).perform(
ViewActions.scrollTo(),
UiInteractions.touchCenterMiddle()
)
onView(
allOf(
withId(R.id.color_picker_tab_icon),
UiMatcher.withBackground(R.drawable.ic_color_picker_tab_rgba)
)
).perform(click())
onColorPickerView()
.onPositiveButton()
.perform(click())
onDrawingSurfaceView()
.perform(
UiInteractions.swipe(
DrawingSurfaceLocationProvider.MIDDLE,
DrawingSurfaceLocationProvider.BOTTOM_MIDDLE
)
)

val selectedColor = toolReference?.tool?.drawPaint!!.color
onDrawingSurfaceView()
.checkPixelColor(selectedColor, BitmapLocationProvider.MIDDLE)
}

fun testSprayRadiusToStrokeWidthStaysConsistent() {
ToolBarViewInteraction.onToolBarView().performSelectTool(ToolType.BRUSH)

Expand Down
1 change: 1 addition & 0 deletions Paintroid/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

<uses-permission
android:name="android.permission.DUMP"
Expand Down
1 change: 1 addition & 0 deletions Paintroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />

Expand Down
6 changes: 3 additions & 3 deletions Paintroid/src/main/java/org/catrobat/paintroid/FileIO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ object FileIO {
cursor?.use {
if (cursor.moveToFirst()) {
fileName =
cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME))
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DISPLAY_NAME))
}
}
if (fileName.endsWith(FileType.JPG.toExtension()) || fileName.endsWith(".jpeg")) {
Expand Down Expand Up @@ -406,9 +406,9 @@ object FileIO {
val cursor = resolver.query(contentLocationUri, null, selection, selectionArgs, null)
cursor?.run {
while (moveToNext()) {
val fileName = getString(cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME))
val fileName = getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME))
if (fileName == filename) {
val id = cursor.getLong(cursor.getColumnIndex(MediaStore.MediaColumns._ID))
val id = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns._ID))
close()
return ContentUris.withAppendedId(contentLocationUri, id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface MainActivityContracts {
interface Navigator {
val isSdkAboveOrEqualM: Boolean
val isSdkAboveOrEqualQ: Boolean
val isSdkAboveOrEqualT: Boolean

fun showColorPickerDialog()

Expand Down
19 changes: 11 additions & 8 deletions Paintroid/src/main/java/org/catrobat/paintroid/model/LayerModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,20 @@ open class LayerModel : LayerContracts.Model {
false
}

@Synchronized
override fun getBitmapOfAllLayers(): Bitmap? {
if (layers.isEmpty()) {
return null
}
val referenceBitmap = layers[0].bitmap
val bitmap = Bitmap.createBitmap(referenceBitmap.width, referenceBitmap.height, Bitmap.Config.ARGB_8888)
val canvas = bitmap?.let { Canvas(it) }
synchronized(this) {
if (layers.isEmpty()) {
return null
}
val referenceBitmap = layers[0].bitmap
val bitmap = Bitmap.createBitmap(referenceBitmap.width, referenceBitmap.height, Bitmap.Config.ARGB_8888)
val canvas = bitmap?.let { Canvas(it) }

drawLayersOntoCanvas(canvas)
drawLayersOntoCanvas(canvas)

return bitmap
return bitmap
}
}

override fun getBitmapListOfAllLayers(): List<Bitmap?> = layers.map { it.bitmap }
Expand Down
Loading

0 comments on commit ebb7a6f

Please sign in to comment.