From c3cd4ff7ea18d18eb6862ee4b03aa4b8cffeb10e Mon Sep 17 00:00:00 2001 From: Tim Celec Date: Fri, 1 Sep 2023 11:39:13 +0200 Subject: [PATCH] PAINTROID-624 Icon update --- .../test/espresso/ToolPixelIntegrationTest.kt | 6 -- .../tools/PixelationToolIntegrationTest.kt | 60 +++---------- .../org/catrobat/paintroid/tools/ToolType.kt | 3 +- .../implementation/DefaultToolFactory.kt | 12 ++- .../tools/implementation/PixelTool.kt | 19 ++-- .../tools/implementation/TransformTool.kt | 2 +- .../options/PixelationToolOptionsView.kt | 16 +--- .../ui/tools/DefaultPixelToolOptionsView.kt | 68 ++++---------- .../drawable/ic_pocketpaint_tool_pixel.xml | 89 +++++++++++++++++-- .../res/layout/dialog_pocketpaint_pixel.xml | 2 - 10 files changed, 132 insertions(+), 145 deletions(-) delete mode 100644 Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ToolPixelIntegrationTest.kt diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ToolPixelIntegrationTest.kt b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ToolPixelIntegrationTest.kt deleted file mode 100644 index 2a9b711310..0000000000 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ToolPixelIntegrationTest.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.catrobat.paintroid.test.espresso - -import org.junit.Test - -class ToolPixelIntegrationTest { -} \ No newline at end of file diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/tools/PixelationToolIntegrationTest.kt b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/tools/PixelationToolIntegrationTest.kt index 85bb2802e1..a132e72c91 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/tools/PixelationToolIntegrationTest.kt +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/tools/PixelationToolIntegrationTest.kt @@ -1,50 +1,29 @@ package org.catrobat.paintroid.test.espresso.tools -import android.graphics.Bitmap -import android.graphics.Color -import android.graphics.PointF -import android.widget.SeekBar import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.PerformException -import androidx.test.espresso.action.ViewActions.* -import androidx.test.espresso.assertion.ViewAssertions +import androidx.test.espresso.action.ViewActions.closeSoftKeyboard +import androidx.test.espresso.action.ViewActions.replaceText +import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.matcher.ViewMatchers.* -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.filters.LargeTest +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.rule.ActivityTestRule -import kotlinx.coroutines.delay -import kotlinx.coroutines.runBlocking import org.catrobat.paintroid.MainActivity import org.catrobat.paintroid.R import org.catrobat.paintroid.contract.LayerContracts -import org.catrobat.paintroid.test.espresso.util.DrawingSurfaceLocationProvider -import org.catrobat.paintroid.test.espresso.util.EspressoUtils.waitForToast import org.catrobat.paintroid.test.espresso.util.MainActivityHelper -import org.catrobat.paintroid.test.espresso.util.UiInteractions -import org.catrobat.paintroid.test.espresso.util.wrappers.DrawingSurfaceInteraction.Companion.onDrawingSurfaceView -import org.catrobat.paintroid.test.espresso.util.wrappers.LayerMenuViewInteraction import org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction -import org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction.Companion.onToolBarView -import org.catrobat.paintroid.test.espresso.util.wrappers.ToolPropertiesInteraction -import org.catrobat.paintroid.test.espresso.util.wrappers.TopBarViewInteraction -import org.catrobat.paintroid.test.espresso.util.wrappers.TransformToolOptionsViewInteraction.Companion.onTransformToolOptionsView import org.catrobat.paintroid.test.utils.ScreenshotOnFailRule import org.catrobat.paintroid.tools.ToolReference import org.catrobat.paintroid.tools.ToolType -import org.catrobat.paintroid.tools.implementation.* +import org.catrobat.paintroid.tools.implementation.MAXIMUM_BITMAP_SIZE_FACTOR +import org.catrobat.paintroid.tools.implementation.PixelTool import org.catrobat.paintroid.ui.Perspective -import org.hamcrest.Matchers.equalTo -import org.hamcrest.Matchers.greaterThan -import org.hamcrest.Matchers.lessThan -import org.hamcrest.Matchers.not import org.junit.Assert.assertEquals -import org.junit.Assert.assertThat -import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Rule import org.junit.Test -import org.junit.runner.RunWith class PixelationToolIntegrationTest { @get:Rule @@ -64,23 +43,8 @@ class PixelationToolIntegrationTest { private lateinit var toolReference: ToolReference private lateinit var mainActivity: MainActivity private lateinit var activityHelper: MainActivityHelper - private lateinit var pixelTool : PixelTool + private lateinit var pixelTool: PixelTool - private var toolSelectionBoxHeight: Float - get() { - return (toolReference.tool as BaseToolWithRectangleShape).boxHeight - } - private set(height) { - (toolReference.tool as BaseToolWithRectangleShape).boxHeight = height - } - - private var toolSelectionBoxWidth: Float - get() { - return (toolReference.tool as BaseToolWithRectangleShape).boxWidth - } - private set(width) { - (toolReference.tool as BaseToolWithRectangleShape).boxWidth = width - } @Before fun setUp() { mainActivity = launchActivityRule.activity @@ -101,9 +65,7 @@ class PixelationToolIntegrationTest { } @Test - fun inputeTest() - { - + fun inputeTest() { var width = 80.0f var height = 49.0f onView(withId(R.id.pocketpaint_pixel_width_value)) @@ -133,4 +95,4 @@ class PixelationToolIntegrationTest { assertEquals(pixelTool.numPixelHeight, height) // assertEquals(pixelTool.numCollors.toInt(),collor ) } -} \ No newline at end of file +} diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/ToolType.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/ToolType.kt index d25dcb7f9c..c90685081e 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/ToolType.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/ToolType.kt @@ -214,8 +214,7 @@ enum class ToolType( R.id.pocketpaint_tools_clipping, INVALID_RESOURCE_ID, true - ) - , + ), PIXEL( R.string.button_pixel, R.string.help_content_text, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/DefaultToolFactory.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/DefaultToolFactory.kt index 4743f691e7..2b6ef50b22 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/DefaultToolFactory.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/DefaultToolFactory.kt @@ -29,7 +29,15 @@ import org.catrobat.paintroid.tools.ToolPaint import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.Workspace import org.catrobat.paintroid.tools.options.ToolOptionsViewController -import org.catrobat.paintroid.ui.tools.* +import org.catrobat.paintroid.ui.tools.DefaultBrushToolOptionsView +import org.catrobat.paintroid.ui.tools.DefaultClipboardToolOptionsView +import org.catrobat.paintroid.ui.tools.DefaultShapeToolOptionsView +import org.catrobat.paintroid.ui.tools.DefaultFillToolOptionsView +import org.catrobat.paintroid.ui.tools.DefaultTransformToolOptionsView +import org.catrobat.paintroid.ui.tools.DefaultTextToolOptionsView +import org.catrobat.paintroid.ui.tools.DefaultSprayToolOptionsView +import org.catrobat.paintroid.ui.tools.DefaultPixelToolOptionsView +import org.catrobat.paintroid.ui.tools.DefaultSmudgeToolOptionsView private const val DRAW_TIME_INIT: Long = 30_000_000 @@ -196,7 +204,7 @@ class DefaultToolFactory(mainActivity: MainActivity) : ToolFactory { DRAW_TIME_INIT, mainActivity ) - ToolType.PIXEL ->PixelTool( + ToolType.PIXEL -> PixelTool( DefaultPixelToolOptionsView(toolLayout), contextCallback, toolOptionsViewController, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PixelTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PixelTool.kt index 18ef259a77..96b59c695c 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PixelTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PixelTool.kt @@ -2,7 +2,6 @@ package org.catrobat.paintroid.tools.implementation import android.graphics.Bitmap import android.graphics.PointF -import android.widget.Toast import androidx.annotation.VisibleForTesting import androidx.test.espresso.idling.CountingIdlingResource import org.catrobat.paintroid.command.CommandManager @@ -15,16 +14,15 @@ import org.catrobat.paintroid.tools.options.ToolOptionsViewController import org.catrobat.paintroid.ui.tools.DefaultPixelToolOptionsView class PixelTool( - pixelToolOptionsViewParam : PixelationToolOptionsView, - contextCallback : ContextCallback, + pixelToolOptionsViewParam: PixelationToolOptionsView, + contextCallback: ContextCallback, toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, idlingResource: CountingIdlingResource, commandManager: CommandManager, override var drawTime: Long -) : BaseToolWithRectangleShape(contextCallback, toolOptionsViewController,toolPaint, workspace, idlingResource, commandManager) -{ +) : BaseToolWithRectangleShape(contextCallback, toolOptionsViewController, toolPaint, workspace, idlingResource, commandManager) { private val pixelToolOptionsView: PixelationToolOptionsView @VisibleForTesting @JvmField @@ -46,7 +44,7 @@ class PixelTool( this.pixelToolOptionsView = pixelToolOptionsViewParam setBitmap(Bitmap.createBitmap(boxWidth.toInt(), boxHeight.toInt(), Bitmap.Config.ARGB_8888)) toolOptionsViewController.showDelayed() - this.pixelToolOptionsView.setPixelPreviewListener(object : PixelationToolOptionsView.OnPixelationPreviewListener { + this.pixelToolOptionsView.setPixelPreviewListener(object : PixelationToolOptionsView.OnPixelationPreviewListener { override fun setPixelWidth(widthPixels: Float) { this@PixelTool.numPixelWidth = widthPixels } @@ -58,11 +56,9 @@ class PixelTool( override fun setNumCollor(collorNum: Float) { this@PixelTool.numCollors = collorNum } - }) } - override val toolType: ToolType get() = ToolType.PIXEL @@ -74,15 +70,12 @@ class PixelTool( super.handleDown(coordinate) } - override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate + override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate // is the checkmark to run the programm override fun onClickOnButton() { // test if the ui works good then shoudl be enought for the 30.8 - var i = 10 - } override fun resetInternalState() = Unit - -} \ No newline at end of file +} diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TransformTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TransformTool.kt index b95af6ace7..ce4dd51dac 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TransformTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TransformTool.kt @@ -371,7 +371,7 @@ class TransformTool( } } - private fun onApplyResizeClicked(resizePercentage: Int) { + private fun onApplyResizeClicked(resizePercentage: Int) { val newWidth = (workspace.width / HUNDRED * resizePercentage).toInt() val newHeight = (workspace.height / HUNDRED * resizePercentage).toInt() if (newWidth == 0 || newHeight == 0) { diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/options/PixelationToolOptionsView.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/options/PixelationToolOptionsView.kt index a78e16c1fc..7fa8cef471 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/options/PixelationToolOptionsView.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/options/PixelationToolOptionsView.kt @@ -1,24 +1,14 @@ package org.catrobat.paintroid.tools.options -import android.view.View - interface PixelationToolOptionsView { - fun invalidate () - - fun getTopToolOptions(): View - - fun getBottomToolOptions(): View fun setPixelPreviewListener(onPixelationPreviewListener: OnPixelationPreviewListener) - interface OnPixelationPreviewListener{ - fun setPixelWidth(widthPixels : Float) + interface OnPixelationPreviewListener { + fun setPixelWidth(widthPixels: Float) - fun setPixelHeight(heightPixels : Float) + fun setPixelHeight(heightPixels: Float) fun setNumCollor(collorNum: Float) } } - - - diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/tools/DefaultPixelToolOptionsView.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/tools/DefaultPixelToolOptionsView.kt index 9cf0aa0994..48c646d02c 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/tools/DefaultPixelToolOptionsView.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/tools/DefaultPixelToolOptionsView.kt @@ -22,52 +22,40 @@ import java.text.NumberFormat import java.text.ParseException import java.util.Locale -@VisibleForTesting - -private const val MIN_WIDTH = 1 -private const val MAX_WIDTH = 100 -private const val MIN_HEIGHT = 1 -private const val MAX_HEIGHT = 200 private const val MIN_COLOR = 1 private const val MAX_COLOR = 40 -// ask PO maybe nee ded the minumum but the bar is not scalable so far (API 21 is current?) - -@SuppressLint("SetTextI18n") -class DefaultPixelToolOptionsView (rootView : ViewGroup): PixelationToolOptionsView{ - - private val pixelNumWidth : AppCompatEditText - private val pixelNumHeight : AppCompatEditText - private var colorNumText : AppCompatEditText - //private val thisLayer : Chip - private val currentView = rootView - private var pixelChangedListener : OnPixelationPreviewListener? = null - private var pixelNumWidthWatcher : PixelToolNumTextWatcher - private var pixelNumHeightWatcher : PixelToolNumTextWatcher - private var colorNumBar : AppCompatSeekBar +@SuppressLint("NotImplementedDeclaration") +class DefaultPixelToolOptionsView(rootView: ViewGroup) : PixelationToolOptionsView { + private val pixelNumWidth: AppCompatEditText + private val pixelNumHeight: AppCompatEditText + private var colorNumText: AppCompatEditText + // private val thisLayer : Chip + // private val currentView = rootView + private var pixelChangedListener: OnPixelationPreviewListener? = null + private var pixelNumWidthWatcher: PixelToolNumTextWatcher + private var pixelNumHeightWatcher: PixelToolNumTextWatcher + private var colorNumBar: AppCompatSeekBar companion object { private val TAG = DefaultPixelToolOptionsView::class.java.simpleName - public val defaulWidth = 40f - public val defaultHeight = 60f - public val defaultCollor = 20f + const val defaulWidth = 40f + const val defaultHeight = 60f + const val defaultCollor = 20f } init { - val inflater = LayoutInflater.from(rootView.context) + val inflater = LayoutInflater.from(rootView.context) val pixelView = inflater.inflate(R.layout.dialog_pocketpaint_pixel, rootView, true) colorNumBar = pixelView.findViewById(R.id.pocketpaint_pixel_color_seekbar) colorNumText = pixelView.findViewById(R.id.pocketpaint_transform_pixel_color_text) colorNumBar.progress = defaultCollor.toInt() colorNumText.setText(String.format(Locale.getDefault(), "%d", colorNumBar.progress)) - pixelNumWidth =pixelView.findViewById(R.id.pocketpaint_pixel_width_value) + pixelNumWidth = pixelView.findViewById(R.id.pocketpaint_pixel_width_value) pixelNumHeight = pixelView.findViewById(R.id.pocketpaint_pixel_height_value) pixelNumWidth.setText(defaulWidth.toString()) pixelNumHeight.setText(defaultHeight.toString()) - // initColorText() - // initWidthText() - // initHeightText() pixelNumWidthWatcher = object : PixelToolNumTextWatcher() { override fun setValue(value: Float) { @@ -81,8 +69,6 @@ class DefaultPixelToolOptionsView (rootView : ViewGroup): PixelationToolOptionsV } pixelNumWidth.addTextChangedListener(pixelNumWidthWatcher) pixelNumHeight.addTextChangedListener(pixelNumHeightWatcher) - // pixelNumHeight.setText(MAX_HEIGHT) - // pixelNumWidth.setText(MAX_WIDTH) colorNumText.filters = arrayOf(DefaultNumberRangeFilter(MIN_COLOR, MAX_COLOR)) colorNumText.setText(String.format(Locale.getDefault(), "%d", colorNumBar.progress)) colorNumText.addTextChangedListener(object : TextWatcher { @@ -124,32 +110,14 @@ class DefaultPixelToolOptionsView (rootView : ViewGroup): PixelationToolOptionsV pixelChangedListener?.setNumCollor(colorNumBar.progress.toFloat()) } - - - } - // handle up probs error - - override fun invalidate() { - TODO("Not yet implemented") - } - - override fun getTopToolOptions(): View { - TODO("Not yet implemented") - } //topLayout - - override fun getBottomToolOptions(): View { - TODO("Not yet implemented") } override fun setPixelPreviewListener(onPixelationPreviewListener: PixelationToolOptionsView.OnPixelationPreviewListener) { this.pixelChangedListener = onPixelationPreviewListener } - abstract class PixelToolNumTextWatcher : TextWatcher { - protected abstract fun setValue(value: Float) - override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) = Unit override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) = Unit @@ -157,7 +125,6 @@ class DefaultPixelToolOptionsView (rootView : ViewGroup): PixelationToolOptionsV var str = editable.toString() if (str.isEmpty()) { str = MAX_COLOR.toString() - } try { val value = NumberFormat.getIntegerInstance().parse(str)?.toFloat() @@ -167,5 +134,4 @@ class DefaultPixelToolOptionsView (rootView : ViewGroup): PixelationToolOptionsV } } } - -} \ No newline at end of file +} diff --git a/Paintroid/src/main/res/drawable/ic_pocketpaint_tool_pixel.xml b/Paintroid/src/main/res/drawable/ic_pocketpaint_tool_pixel.xml index 886c3171da..fd487bddbc 100644 --- a/Paintroid/src/main/res/drawable/ic_pocketpaint_tool_pixel.xml +++ b/Paintroid/src/main/res/drawable/ic_pocketpaint_tool_pixel.xml @@ -1,9 +1,86 @@ + android:width="48dp" + android:height="48dp" + android:viewportWidth="48" + android:viewportHeight="48"> + android:pathData="M7.5,7.5h6v6h-6z" + android:strokeWidth="3" + android:fillColor="#00000000" + android:strokeColor="#000000"/> + + + + + + + + + + + + + + + diff --git a/Paintroid/src/main/res/layout/dialog_pocketpaint_pixel.xml b/Paintroid/src/main/res/layout/dialog_pocketpaint_pixel.xml index 53c0668408..e512d0b85b 100644 --- a/Paintroid/src/main/res/layout/dialog_pocketpaint_pixel.xml +++ b/Paintroid/src/main/res/layout/dialog_pocketpaint_pixel.xml @@ -111,8 +111,6 @@ android:layout_width="21dp" /> - -