From bda06d83e6c7622cda9ff9c43e4608aa6417f45b Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 25 Nov 2021 15:55:06 +0100 Subject: [PATCH 01/36] PAINTROID-355 Color of the lower layer remains yellow if swiped right while merging --- .../org/catrobat/paintroid/contract/LayerContracts.kt | 2 ++ .../org/catrobat/paintroid/presenter/LayerPresenter.kt | 10 ++++++++++ .../java/org/catrobat/paintroid/ui/LayerAdapter.kt | 6 ++++++ .../paintroid/ui/dragndrop/DragAndDropListView.kt | 4 ++++ 4 files changed, 22 insertions(+) diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/contract/LayerContracts.kt b/Paintroid/src/main/java/org/catrobat/paintroid/contract/LayerContracts.kt index 084ed5dff8..32216267a8 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/contract/LayerContracts.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/contract/LayerContracts.kt @@ -87,6 +87,8 @@ interface LayerContracts { fun setMergable() + fun isSelected(): Boolean + fun setCheckBox(setTo: Boolean) } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/presenter/LayerPresenter.kt b/Paintroid/src/main/java/org/catrobat/paintroid/presenter/LayerPresenter.kt index 3440b44f1e..8324629ff4 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/presenter/LayerPresenter.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/presenter/LayerPresenter.kt @@ -257,4 +257,14 @@ class LayerPresenter( adapter?.notifyDataSetChanged() listItemLongClickHandler.stopDragging() } + + fun resetMergeColor(layerPosition: Int) { + if (adapter != null && adapter?.getViewHolderAt(layerPosition) != null) { + if (adapter?.getViewHolderAt(layerPosition)!!.isSelected()) { + adapter?.getViewHolderAt(layerPosition)?.setSelected() + } else { + adapter?.getViewHolderAt(layerPosition)?.setDeselected() + } + } + } } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/LayerAdapter.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/LayerAdapter.kt index eee0988bbe..db0c72a6b5 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/LayerAdapter.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/LayerAdapter.kt @@ -90,6 +90,7 @@ class LayerAdapter(val presenter: LayerContracts.Presenter) : BaseAdapter(), Lay private val imageView: ImageView = itemView.findViewById(R.id.pocketpaint_item_layer_image) private var currentBitmap: Bitmap? = null private val checkBox: CheckBox = itemView.findViewById(R.id.pocketpaint_checkbox_layer) + private var isSelected = false companion object { private const val RESIZE_LENGTH = 400f @@ -107,16 +108,21 @@ class LayerAdapter(val presenter: LayerContracts.Presenter) : BaseAdapter(), Lay bottomNavigationViewHolder?.showCurrentTool(ToolType.HAND) } layerBackground.setBackgroundColor(Color.BLUE) + isSelected = true } override fun setSelected() { layerBackground.setBackgroundColor(Color.BLUE) + isSelected = true } override fun setDeselected() { layerBackground.setBackgroundColor(Color.TRANSPARENT) + isSelected = false } + override fun isSelected() = isSelected + override fun updateImageView(bitmap: Bitmap?, isDrawerLayoutOpen: Boolean) { if (isDrawerLayoutOpen) { runBlocking { diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/dragndrop/DragAndDropListView.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/dragndrop/DragAndDropListView.kt index 6741198066..f147ec1540 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/dragndrop/DragAndDropListView.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/dragndrop/DragAndDropListView.kt @@ -33,6 +33,7 @@ import android.view.View import android.widget.AdapterView.OnItemClickListener import android.widget.AdapterView.OnItemLongClickListener import android.widget.ListView +import org.catrobat.paintroid.presenter.LayerPresenter import kotlin.math.max import kotlin.math.min @@ -109,6 +110,9 @@ class DragAndDropListView : ListView, ListItemLongClickHandler { override fun stopDragging() { hoveringListItem ?: return + if (presenter is LayerPresenter) { + (presenter as LayerPresenter).resetMergeColor(mergePosition) + } mergePosition = -1 view?.visibility = VISIBLE view = null From bd5ad7ce18040af5f2f8c3b08cf0633f1fb0d4ec Mon Sep 17 00:00:00 2001 From: GOMBOCZ Michael Date: Thu, 27 Jan 2022 22:05:58 +0100 Subject: [PATCH 02/36] PAINTROID-371 Handling invalid layer accesses --- .../command/LoadBitmapListCommandTest.kt | 6 +-- .../junit/command/MergeLayersCommandTest.kt | 12 +++--- .../paintroid/test/junit/model/LayerTest.java | 42 +++++++++++++++++-- .../implementation/DefaultCommandManager.kt | 41 ++++++++++++++---- .../implementation/MergeLayersCommand.kt | 34 ++++++++++----- .../implementation/RemoveLayerCommand.kt | 7 ++-- .../implementation/ReorderLayersCommand.kt | 20 +++++++-- .../paintroid/contract/LayerContracts.kt | 8 ++-- .../catrobat/paintroid/model/LayerModel.kt | 21 ++++++---- .../paintroid/presenter/LayerPresenter.kt | 39 +++++++++-------- 10 files changed, 162 insertions(+), 68 deletions(-) diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/command/LoadBitmapListCommandTest.kt b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/command/LoadBitmapListCommandTest.kt index 27b1ee9dfc..0b697b9188 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/command/LoadBitmapListCommandTest.kt +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/command/LoadBitmapListCommandTest.kt @@ -1,6 +1,6 @@ /* * Paintroid: An image manipulation application for Android. - * Copyright (C) 2010-2021 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -53,8 +53,8 @@ class LoadBitmapListCommandTest { fun testRunCopiesImage() { commandUnderTest.run(canvas, layerModel) Assert.assertTrue(layerModel.currentLayer!!.bitmap!!.sameAs(bitmapList[0])) - Assert.assertTrue(layerModel.getLayerAt(1).bitmap!!.sameAs(bitmapList[1])) - Assert.assertTrue(layerModel.getLayerAt(2).bitmap!!.sameAs(bitmapList[2])) + Assert.assertTrue(layerModel.getLayerAt(1)!!.bitmap!!.sameAs(bitmapList[1])) + Assert.assertTrue(layerModel.getLayerAt(2)!!.bitmap!!.sameAs(bitmapList[2])) } @Test diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/command/MergeLayersCommandTest.kt b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/command/MergeLayersCommandTest.kt index d7dc40d485..7dcdb3c100 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/command/MergeLayersCommandTest.kt +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/command/MergeLayersCommandTest.kt @@ -1,6 +1,6 @@ /* * Paintroid: An image manipulation application for Android. - * Copyright (C) 2010-2021 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -74,10 +74,10 @@ class MergeLayersCommandTest { @Test fun testRun() { commandUnderTest.run(canvasUnderTest, layerModel) - Assert.assertEquals(layerModel.getLayerAt(0).bitmap!!.getPixel(5, 5), PAINT_BASE_COLOR) - Assert.assertEquals(layerModel.getLayerAt(0).bitmap!!.getPixel(8, 8), PAINT_BASE_COLOR) - Assert.assertEquals(layerModel.getLayerAt(0).bitmap!!.getPixel(3, 3), 0) - Assert.assertEquals(layerModel.getLayerAt(0).bitmap!!.getPixel(0, 0), 0) + Assert.assertEquals(layerModel.getLayerAt(0)!!.bitmap!!.getPixel(5, 5), PAINT_BASE_COLOR) + Assert.assertEquals(layerModel.getLayerAt(0)!!.bitmap!!.getPixel(8, 8), PAINT_BASE_COLOR) + Assert.assertEquals(layerModel.getLayerAt(0)!!.bitmap!!.getPixel(3, 3), 0) + Assert.assertEquals(layerModel.getLayerAt(0)!!.bitmap!!.getPixel(0, 0), 0) } @Test @@ -96,6 +96,6 @@ class MergeLayersCommandTest { Assert.assertEquals(layerModel.currentLayer!!.bitmap!!.getPixel(8, 8), PAINT_BASE_COLOR) Assert.assertEquals(layerModel.currentLayer!!.bitmap!!.getPixel(3, 3), 0) Assert.assertEquals(layerModel.currentLayer!!.bitmap!!.getPixel(5, 5), 0) - Assert.assertEquals(layerModel.getLayerAt(1).bitmap!!.getPixel(5, 5), PAINT_BASE_COLOR) + Assert.assertEquals(layerModel.getLayerAt(1)!!.bitmap!!.getPixel(5, 5), PAINT_BASE_COLOR) } } diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/model/LayerTest.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/model/LayerTest.java index c2255477f5..8b9a5c0cb4 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/model/LayerTest.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/model/LayerTest.java @@ -1,6 +1,6 @@ /* * Paintroid: An image manipulation application for Android. - * Copyright (C) 2010-2015 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -39,7 +39,11 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.timeout; @@ -50,14 +54,16 @@ public class LayerTest { private CommandFactory commandFactory; private CommandManager commandManager; private LayerContracts.Model layerModel; + private final int layerHeight = 200; + private final int layerWidth = 200; @Before public void setUp() { commandFactory = new DefaultCommandFactory(); layerModel = new LayerModel(); - layerModel.setWidth(200); - layerModel.setHeight(200); - Layer layer = new Layer(Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888)); + layerModel.setWidth(layerWidth); + layerModel.setHeight(layerHeight); + Layer layer = new Layer(Bitmap.createBitmap(layerWidth, layerHeight, Bitmap.Config.ARGB_8888)); layerModel.addLayerAt(0, layer); layerModel.setCurrentLayer(layer); @@ -155,4 +161,32 @@ public void testHideThenUnhideLayer() { assertThat(layerToHide.getBitmap().getPixel(3, 1), is(Color.BLACK)); assertThat(layerToHide.getBitmap().getPixel(4, 1), is(Color.BLACK)); } + + @Test + public void testGetLayerAt() { + for (int i = 0; i < layerModel.getLayerCount(); i++) { + assertNotNull(layerModel.getLayerAt(i)); + } + + assertNull(layerModel.getLayerAt(-1)); + assertNull(layerModel.getLayerAt(layerModel.getLayerCount())); + } + + @Test + public void testAddLayerAt() { + Layer layer = new Layer(Bitmap.createBitmap(layerWidth, layerHeight, Bitmap.Config.ARGB_8888)); + assertTrue(layerModel.addLayerAt(0, layer)); + assertTrue(layerModel.addLayerAt(layerModel.getLayerCount(), layer)); + assertFalse(layerModel.addLayerAt(-1, layer)); + assertFalse(layerModel.addLayerAt(layerModel.getLayerCount() + 1, layer)); + } + + @Test + public void testRemoveLayerAt() { + assertFalse(layerModel.removeLayerAt(-1)); + assertTrue(layerModel.removeLayerAt(0)); + Layer layer = new Layer(Bitmap.createBitmap(layerWidth, layerHeight, Bitmap.Config.ARGB_8888)); + layerModel.addLayerAt(0, layer); + assertFalse(layerModel.removeLayerAt(layerModel.getLayerCount())); + } } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/DefaultCommandManager.kt b/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/DefaultCommandManager.kt index 1e355000c5..5ee291a933 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/DefaultCommandManager.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/DefaultCommandManager.kt @@ -1,6 +1,6 @@ /* * Paintroid: An image manipulation application for Android. - * Copyright (C) 2010-2021 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -90,23 +90,37 @@ class DefaultCommandManager( } override fun undo() { + var success = true val command = undoCommandList.pop() redoCommandList.addFirst(command) - var layerCount = layerModel.layerCount val currentCommandName = command.javaClass.simpleName val addLayerCommandRegex = AddLayerCommand::class.java.simpleName.toRegex() val mergeLayerCommandRegex = MergeLayersCommand::class.java.simpleName.toRegex() + var backupLayer: LayerContracts.Layer? = null if (currentCommandName.matches(addLayerCommandRegex)) { layerCount-- - layerModel.removeLayerAt(0) + backupLayer = layerModel.getLayerAt(0) + success = layerModel.removeLayerAt(0) } val checkBoxes: MutableList = ArrayList(Collections.nCopies(layerCount, true)) if (!currentCommandName.matches(mergeLayerCommandRegex)) { - backUpCheckBoxes(layerCount, checkBoxes) + success = if (!backUpCheckBoxes(layerCount, checkBoxes)) false else success + } + + if (!success) { + backupLayer?.apply { + if (layerModel.getLayerIndexOf(this) == -1) { + layerModel.addLayerAt(0, this) + } + } + val commandToRestore = redoCommandList.pop() + undoCommandList.addFirst(commandToRestore) + + return } layerModel.reset() @@ -172,14 +186,21 @@ class DefaultCommandManager( } } - private fun backUpCheckBoxes(layerCount: Int, checkBoxes: MutableList) { + private fun backUpCheckBoxes(layerCount: Int, checkBoxes: MutableList): Boolean { + var success = true if (layerCount > 1) { for (index in layerCount - 1 downTo 0) { - checkBoxes[index] = layerModel.getLayerAt(index).checkBox + layerModel.getLayerAt(index)?.let { + checkBoxes[index] = it.checkBox + } ?: run { success = false } } } else { - checkBoxes[0] = layerModel.getLayerAt(0).checkBox + layerModel.getLayerAt(0)?.let { + checkBoxes[0] = it.checkBox + } ?: run { success = false } } + + return success } private fun fetchBackCheckBoxes(layerCount: Int, checkBoxes: List) { @@ -187,8 +208,10 @@ class DefaultCommandManager( for (index in layerCount - 1 downTo 0) { val destinationLayer = layerModel.getLayerAt(index) if (!checkBoxes[index]) { - destinationLayer.switchBitmaps(false) - destinationLayer.checkBox = false + destinationLayer?.let { + it.switchBitmaps(false) + it.checkBox = false + } } } } else { diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/MergeLayersCommand.kt b/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/MergeLayersCommand.kt index 69fac35799..c4b43491f6 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/MergeLayersCommand.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/MergeLayersCommand.kt @@ -1,6 +1,6 @@ /* * Paintroid: An image manipulation application for Android. - * Copyright (C) 2010-2021 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -20,6 +20,7 @@ package org.catrobat.paintroid.command.implementation import android.graphics.Canvas +import android.util.Log import org.catrobat.paintroid.command.Command import org.catrobat.paintroid.contract.LayerContracts @@ -28,18 +29,31 @@ class MergeLayersCommand(position: Int, mergeWith: Int) : Command { var position = position; private set var mergeWith = mergeWith; private set + companion object { + private val TAG = MergeLayersCommand::class.java.simpleName + } + override fun run(canvas: Canvas, layerModel: LayerContracts.Model) { val sourceLayer = layerModel.getLayerAt(position) val destinationLayer = layerModel.getLayerAt(mergeWith) - val destinationBitmap = destinationLayer.bitmap - destinationBitmap ?: return - val copyBitmap = destinationBitmap.copy(destinationBitmap.config, true) - val copyCanvas = Canvas(copyBitmap) - copyCanvas.drawBitmap(sourceLayer.bitmap ?: return, 0f, 0f, null) - destinationLayer.bitmap = copyBitmap - layerModel.removeLayerAt(position) - if (sourceLayer === layerModel.currentLayer) { - layerModel.currentLayer = destinationLayer + var success = false + if (sourceLayer != null && destinationLayer != null) { + val destinationBitmap = destinationLayer.bitmap + destinationBitmap ?: return + val copyBitmap = destinationBitmap.copy(destinationBitmap.config, true) + val copyCanvas = Canvas(copyBitmap) + copyCanvas.drawBitmap(sourceLayer.bitmap ?: return, 0f, 0f, null) + if (layerModel.removeLayerAt(position)) { + destinationLayer.bitmap = copyBitmap + if (sourceLayer == layerModel.currentLayer) { + layerModel.currentLayer = destinationLayer + } + success = true + } + } + + if (!success) { + Log.e(TAG, "Could not merge layers!") } } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/RemoveLayerCommand.kt b/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/RemoveLayerCommand.kt index ad29717f41..46c18ac3dc 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/RemoveLayerCommand.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/RemoveLayerCommand.kt @@ -1,6 +1,6 @@ /* * Paintroid: An image manipulation application for Android. - * Copyright (C) 2010-2021 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -28,8 +28,9 @@ class RemoveLayerCommand(position: Int) : Command { var position = position; private set override fun run(canvas: Canvas, layerModel: LayerContracts.Model) { - layerModel.removeLayerAt(position) - layerModel.currentLayer = layerModel.layers[0] + if (layerModel.removeLayerAt(position)) { + layerModel.getLayerAt(0)?.let { layerModel.currentLayer = it } + } } override fun freeResources() { diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/ReorderLayersCommand.kt b/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/ReorderLayersCommand.kt index fca481c9e9..f3b89684ef 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/ReorderLayersCommand.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/ReorderLayersCommand.kt @@ -1,6 +1,6 @@ /* * Paintroid: An image manipulation application for Android. - * Copyright (C) 2010-2021 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -20,6 +20,7 @@ package org.catrobat.paintroid.command.implementation import android.graphics.Canvas +import android.util.Log import org.catrobat.paintroid.command.Command import org.catrobat.paintroid.contract.LayerContracts @@ -28,11 +29,22 @@ class ReorderLayersCommand(position: Int, destination: Int) : Command { var position = position; private set var destination = destination; private set + companion object { + private val TAG = ReorderLayersCommand::class.java.simpleName + } + override fun run(canvas: Canvas, layerModel: LayerContracts.Model) { layerModel.run { - val tempLayer = getLayerAt(position) - removeLayerAt(position) - addLayerAt(destination, tempLayer) + var success = false + getLayerAt(position)?.let { layer -> + if (removeLayerAt(position)) { + success = addLayerAt(destination, layer) + } + } + + if (!success) { + Log.e(TAG, "Could not retrieve layer to reorder!") + } } } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/contract/LayerContracts.kt b/Paintroid/src/main/java/org/catrobat/paintroid/contract/LayerContracts.kt index 084ed5dff8..de47e80f41 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/contract/LayerContracts.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/contract/LayerContracts.kt @@ -1,6 +1,6 @@ /* * Paintroid: An image manipulation application for Android. - * Copyright (C) 2010-2021 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -117,17 +117,17 @@ interface LayerContracts { fun reset() - fun getLayerAt(index: Int): Layer + fun getLayerAt(index: Int): Layer? fun getLayerIndexOf(layer: Layer): Int - fun addLayerAt(index: Int, layer: Layer) + fun addLayerAt(index: Int, layer: Layer): Boolean fun listIterator(index: Int): ListIterator fun setLayerAt(position: Int, layer: Layer) - fun removeLayerAt(position: Int) + fun removeLayerAt(position: Int): Boolean } interface Navigator { diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/model/LayerModel.kt b/Paintroid/src/main/java/org/catrobat/paintroid/model/LayerModel.kt index 8306e05576..600172a527 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/model/LayerModel.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/model/LayerModel.kt @@ -1,6 +1,6 @@ /* * Paintroid: An image manipulation application for Android. - * Copyright (C) 2010-2021 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -22,12 +22,13 @@ import android.graphics.Bitmap import android.graphics.Canvas import org.catrobat.paintroid.contract.LayerContracts import java.util.ArrayList +import kotlin.IndexOutOfBoundsException class LayerModel : LayerContracts.Model { override var currentLayer: LayerContracts.Layer? = null override var width = 0 override var height = 0 - override val layers: ArrayList = ArrayList() + override val layers: ArrayList = arrayListOf() override val layerCount: Int get() = layers.size @@ -35,12 +36,16 @@ class LayerModel : LayerContracts.Model { layers.clear() } - override fun getLayerAt(index: Int): LayerContracts.Layer = layers[index] + override fun getLayerAt(index: Int): LayerContracts.Layer? = layers.getOrNull(index) override fun getLayerIndexOf(layer: LayerContracts.Layer): Int = layers.indexOf(layer) - override fun addLayerAt(index: Int, layer: LayerContracts.Layer) { + @SuppressWarnings("SwallowedException", "TooGenericExceptionCaught") + override fun addLayerAt(index: Int, layer: LayerContracts.Layer): Boolean = try { layers.add(index, layer) + true + } catch (e: IndexOutOfBoundsException) { + false } override fun listIterator(index: Int): ListIterator = @@ -50,12 +55,15 @@ class LayerModel : LayerContracts.Model { layers[position] = layer } - override fun removeLayerAt(position: Int) { + @SuppressWarnings("SwallowedException", "TooGenericExceptionCaught") + override fun removeLayerAt(position: Int): Boolean = try { layers.removeAt(position) + true + } catch (e: IndexOutOfBoundsException) { + false } companion object { - @JvmStatic fun getBitmapOfAllLayersToSave(layers: List): Bitmap? { if (layers.isEmpty()) { return null @@ -73,7 +81,6 @@ class LayerModel : LayerContracts.Model { return bitmap } - @JvmStatic fun getBitmapListOfAllLayers(layers: List): List { val bitmapList: MutableList = ArrayList() for (layer in layers) { diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/presenter/LayerPresenter.kt b/Paintroid/src/main/java/org/catrobat/paintroid/presenter/LayerPresenter.kt index 3440b44f1e..60f645a2eb 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/presenter/LayerPresenter.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/presenter/LayerPresenter.kt @@ -1,6 +1,6 @@ /* * Paintroid: An image manipulation application for Android. - * Copyright (C) 2010-2021 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -158,7 +158,7 @@ class LayerPresenter( private fun getDestinationLayer( position: Int, isUnhide: Boolean - ): LayerContracts.Layer = model.getLayerAt(position).apply { + ): LayerContracts.Layer? = model.getLayerAt(position)?.apply { if (isUnhide) switchBitmaps(isUnhide) val newBitmap = if (!isUnhide) transparentBitmap else bitmap if (!isUnhide) switchBitmaps(isUnhide) @@ -167,21 +167,23 @@ class LayerPresenter( } override fun hideLayer(position: Int) { - val destinationLayer = getDestinationLayer(position, false) drawingSurface?.refreshDrawingSurface() - if (model.currentLayer == destinationLayer) { - defaultToolController?.switchTool(ToolType.HAND, false) - bottomNavigationViewHolder?.showCurrentTool(ToolType.HAND) + getDestinationLayer(position, false)?.let { layer -> + if (model.currentLayer == layer) { + defaultToolController?.switchTool(ToolType.HAND, false) + bottomNavigationViewHolder?.showCurrentTool(ToolType.HAND) + } } } override fun unhideLayer(position: Int, viewHolder: LayerContracts.LayerViewHolder) { - val destinationLayer = getDestinationLayer(position, true) - viewHolder.updateImageView(destinationLayer.bitmap, true) drawingSurface?.refreshDrawingSurface() - if (model.currentLayer == destinationLayer) { - defaultToolController?.switchTool(ToolType.BRUSH, false) - bottomNavigationViewHolder?.showCurrentTool(ToolType.BRUSH) + getDestinationLayer(position, true)?.let { layer -> + viewHolder.updateImageView(layer.bitmap, true) + if (model.currentLayer == layer) { + defaultToolController?.switchTool(ToolType.BRUSH, false) + bottomNavigationViewHolder?.showCurrentTool(ToolType.BRUSH) + } } } @@ -192,13 +194,14 @@ class LayerPresenter( override fun mergeItems(position: Int, mergeWith: Int) { checkIfLineToolInUse() - val actualLayer = layers[mergeWith] - val actualPosition = model.getLayerIndexOf(actualLayer) - if (position != actualPosition) { - commandManager.addCommand( - commandFactory.createMergeLayersCommand(position, actualPosition) - ) - navigator.showToast(R.string.layer_merged, Toast.LENGTH_SHORT) + layers.getOrNull(mergeWith)?.let { actualLayer -> + val actualPosition = model.getLayerIndexOf(actualLayer) + if (position != actualPosition && actualPosition > -1) { + commandManager.addCommand( + commandFactory.createMergeLayersCommand(position, actualPosition) + ) + navigator.showToast(R.string.layer_merged, Toast.LENGTH_SHORT) + } } } From 31259b9235cffa826b8d495fcd7d2a3002b47d63 Mon Sep 17 00:00:00 2001 From: GOMBOCZ Michael Date: Thu, 10 Feb 2022 17:36:21 +0100 Subject: [PATCH 03/36] PAINTROID-339 TASK: Add PR# and build# to debug apks --- app/build.gradle | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 7c15feb811..1cefb1cbb1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ import io.gitlab.arturbosch.detekt.Detekt /** * Paintroid: An image manipulation application for Android. - * Copyright (C) 2010-2015 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -83,6 +83,23 @@ android { signedRelease { signingConfig signingConfigs.signedRelease } + debug { + def branchName = System.getenv("BRANCH_NAME") + def buildNumber = System.getenv("BUILD_NUMBER") + + //only rename when env is setup via jenkins + if (branchName && buildNumber) { + //loop over all variants is necessary to expose outputFileName variable + android.applicationVariants.all { variant -> + if (variant.name == "debug") { + variant.outputs.all { output -> + def fileName = "${getProperty("archivesBaseName")}-debug-$branchName-${buildNumber}.apk" + outputFileName = fileName + } + } + } + } + } } } From a8d103dd7c2111615ae240497bcb5bb39b4a8bf6 Mon Sep 17 00:00:00 2001 From: julian_jautz Date: Sat, 19 Feb 2022 07:13:42 +0100 Subject: [PATCH 04/36] PAINTROID-369: Crash NullPointerException colorpicker.ZoomableImageView display variable could be null, null check added as display.getSize is deprecated with API level 30, added alternative for newer versions --- .../colorpicker/ZoomableImageView.kt | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/colorpicker/src/main/java/org/catrobat/paintroid/colorpicker/ZoomableImageView.kt b/colorpicker/src/main/java/org/catrobat/paintroid/colorpicker/ZoomableImageView.kt index d4b81a7074..b1fbb625b8 100644 --- a/colorpicker/src/main/java/org/catrobat/paintroid/colorpicker/ZoomableImageView.kt +++ b/colorpicker/src/main/java/org/catrobat/paintroid/colorpicker/ZoomableImageView.kt @@ -1,6 +1,6 @@ /* * Paintroid: An image manipulation application for Android. - * Copyright (C) 2010-2021 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -38,6 +38,8 @@ import android.view.GestureDetector import android.view.MotionEvent import android.view.ScaleGestureDetector import android.view.View +import android.view.WindowInsets +import android.view.WindowManager import androidx.appcompat.widget.AppCompatImageView import androidx.core.content.ContextCompat import androidx.core.view.updateLayoutParams @@ -310,11 +312,24 @@ class ZoomableImageView : private fun updateLP() { updateLayoutParams { - val point = Point() post { - display.getSize(point) - height = point.y - width = point.x + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager + val windowMetrics = windowManager.currentWindowMetrics + val windowInsets = windowMetrics.windowInsets.getInsetsIgnoringVisibility( + WindowInsets.Type.navigationBars() or WindowInsets.Type.displayCutout() + ) + val insetsWidth = windowInsets.right + windowInsets.left + val insetsHeight = windowInsets.top + windowInsets.bottom + val b = windowMetrics.bounds + width = b.width() - insetsWidth + height = b.height() - insetsHeight + } else { + val point = Point() + display?.getSize(point) + height = point.y + width = point.x + } } } } From db5bf99b0228778edebc99c8d7130603e83f887f Mon Sep 17 00:00:00 2001 From: Thorsten Date: Sat, 29 Jan 2022 17:35:47 +0100 Subject: [PATCH 05/36] Testing out how to build Paintroid with Catroid --- Jenkinsfile | 12 ++++++++++-- docker/Dockerfile.jenkins | 3 --- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 00d3f09d85..8df5593f1b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,6 +27,7 @@ pipeline { parameters { string name: 'DEBUG_LABEL', defaultValue: '', description: 'For debugging when entered will be used as label to decide on which slaves the jobs will run.' booleanParam name: 'BUILD_WITH_CATROID', defaultValue: false, description: 'When checked then the current Paintroid build will be built with the current develop branch of Catroid' + string name: 'CATROID_BRANCH', defaultValue: 'develop', description: 'The branch which to build catroid with, when BUILD_WITH_CATROID is checked.' } agent { @@ -74,12 +75,19 @@ pipeline { params.BUILD_WITH_CATROID } } + steps { sh './gradlew publishToMavenLocal -Psnapshot' sh 'rm -rf Catroid; mkdir Catroid' dir('Catroid') { - git branch: 'develop', url: 'https://github.com/Catrobat/Catroid.git' - sh "./gradlew -PpaintroidLocal assembleCatroidDebug" + git branch: params.CATROID_BRANCH, url: 'https://github.com/Catrobat/Catroid.git' + sh 'rm -f catroid/src/main/libs/*.aar' + sh 'mv -f ../colorpicker/build/outputs/aar/colorpicker-debug.aar catroid/src/main/libs/colorpicker-LOCAL.aar' + sh 'mv -f ../Paintroid/build/outputs/aar/Paintroid-debug.aar catroid/src/main/libs/Paintroid-LOCAL.aar' + + archiveArtifacts 'catroid/src/main/libs/colorpicker-LOCAL.aar' + archiveArtifacts 'catroid/src/main/libs/Paintroid-LOCAL.aar' + sh "./gradlew assembleCatroidDebug" archiveArtifacts 'catroid/build/outputs/apk/catroid/debug/catroid-catroid-debug.apk' } } diff --git a/docker/Dockerfile.jenkins b/docker/Dockerfile.jenkins index aa7628a8d9..967c445cd2 100644 --- a/docker/Dockerfile.jenkins +++ b/docker/Dockerfile.jenkins @@ -7,9 +7,6 @@ FROM debian:buster # Android SDK 26.1.1 ARG ANDROID_SDK_URL="https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip" -# Android NDK r18b -ARG ANDROID_NDK_URL="https://dl.google.com/android/repository/android-ndk-r18b-linux-x86_64.zip" - ARG SDKMANAGER_PACKAGES="build-tools;30.0.3 platforms;android-28 cmake;3.6.4111459 system-images;android-28;default;x86_64 emulator platform-tools" # Arguments, Environment # ---------------------- From 9ada668d1618910a4856e2911211cb42f3fbb47e Mon Sep 17 00:00:00 2001 From: David Moling Date: Fri, 11 Mar 2022 17:30:36 +0100 Subject: [PATCH 06/36] PAINTROID-146 set center button in transform tool --- .../tools/TransformToolIntegrationTest.kt | 21 +++ .../TransformToolOptionsViewInteraction.java | 6 + .../BaseToolWithRectangleShapeToolTest.java | 7 +- .../test/junit/tools/BrushToolTest.java | 4 +- .../test/junit/tools/CursorToolTest.java | 4 +- .../test/junit/tools/FillToolTest.java | 4 +- .../test/junit/tools/ImportToolTest.java | 4 +- .../test/junit/tools/LineToolTest.kt | 6 +- .../test/junit/tools/PipetteToolTest.java | 4 +- .../test/junit/tools/ShapeToolTest.java | 4 +- .../test/junit/tools/SprayToolTest.kt | 4 +- .../test/junit/tools/StampToolTest.java | 4 +- .../tools/implementation/BaseTool.kt | 4 +- .../BaseToolWithRectangleShape.kt | 11 +- .../tools/implementation/BaseToolWithShape.kt | 4 +- .../tools/implementation/BrushTool.kt | 4 +- .../tools/implementation/CursorTool.kt | 4 +- .../tools/implementation/EraserTool.kt | 4 +- .../tools/implementation/FillTool.kt | 4 +- .../tools/implementation/ImportTool.kt | 4 +- .../tools/implementation/LineTool.kt | 4 +- .../tools/implementation/PipetteTool.kt | 4 +- .../tools/implementation/ShapeTool.kt | 4 +- .../tools/implementation/SprayTool.kt | 4 +- .../tools/implementation/StampTool.kt | 4 +- .../tools/implementation/TextTool.kt | 3 +- .../tools/implementation/TransformTool.kt | 141 +++++++++++++++++- .../tools/implementation/WatercolorTool.kt | 4 +- .../tools/options/TransformToolOptionsView.kt | 2 + .../tools/DefaultTransformToolOptionsView.kt | 4 + ...c_pocketpaint_tool_center_focus_strong.xml | 12 ++ .../dialog_pocketpaint_transform_tool.xml | 58 ++++--- Paintroid/src/main/res/values/string.xml | 7 +- 33 files changed, 288 insertions(+), 74 deletions(-) create mode 100644 Paintroid/src/main/res/drawable/ic_pocketpaint_tool_center_focus_strong.xml diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/tools/TransformToolIntegrationTest.kt b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/tools/TransformToolIntegrationTest.kt index 736456303f..4f4ee8a475 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/tools/TransformToolIntegrationTest.kt +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/tools/TransformToolIntegrationTest.kt @@ -1334,6 +1334,27 @@ class TransformToolIntegrationTest { assertEquals(scale, perspective.scale, 0.0001f) } + @Test + fun testTransformToolSetCenter() { + drawPlus(layerModel.currentLayer!!.bitmap!!, initialWidth / 2) + onToolBarView() + .performSelectTool(ToolType.TRANSFORM) + + runBlocking { + onTransformToolOptionsView().performSetCenterClick() + } + val maxWidth = maxBitmapSize / initialHeight + val dragFrom = + getSurfacePointFromCanvasPoint(PointF(initialWidth.toFloat(), initialHeight.toFloat())) + val dragTo = getSurfacePointFromCanvasPoint( + PointF(maxWidth + 10f, initialHeight.toFloat()) + ) + onDrawingSurfaceView().perform(UiInteractions.swipe(dragFrom, dragTo)) + runBlocking { + TopBarViewInteraction.onTopBarView().performClickCheckmark() + } + } + companion object { private fun drawPlus(bitmap: Bitmap, lineLength: Int) { val horizontalStartX = bitmap.width / 4 diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/TransformToolOptionsViewInteraction.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/TransformToolOptionsViewInteraction.java index 91f64abb4a..3705ce9b09 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/TransformToolOptionsViewInteraction.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/TransformToolOptionsViewInteraction.java @@ -47,6 +47,12 @@ public static TransformToolOptionsViewInteraction onTransformToolOptionsView() { return new TransformToolOptionsViewInteraction(); } + public TransformToolOptionsViewInteraction performSetCenterClick() { + onView(withId(R.id.pocketpaint_transform_set_center_btn)) + .perform(click()); + return this; + } + public TransformToolOptionsViewInteraction performAutoCrop() { onView(withId(R.id.pocketpaint_transform_auto_crop_btn)) .perform(click()); diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/BaseToolWithRectangleShapeToolTest.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/BaseToolWithRectangleShapeToolTest.java index e3cb7c6f09..6c88724061 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/BaseToolWithRectangleShapeToolTest.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/BaseToolWithRectangleShapeToolTest.java @@ -30,7 +30,7 @@ import org.catrobat.paintroid.tools.ToolType; import org.catrobat.paintroid.tools.Workspace; import org.catrobat.paintroid.tools.implementation.BaseToolWithRectangleShape; -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController; +import org.catrobat.paintroid.tools.options.ToolOptionsViewController; import org.catrobat.paintroid.ui.Perspective; import org.junit.Before; import org.junit.Test; @@ -69,7 +69,7 @@ public class BaseToolWithRectangleShapeToolTest { @Mock private CommandManager commandManager; @Mock - private ToolOptionsVisibilityController toolOptionsViewController; + private ToolOptionsViewController toolOptionsViewController; @Mock private ContextCallback contextCallback; @Mock @@ -376,8 +376,7 @@ public void testToolClicksOnTouchDownPosition() { private class BaseToolWithRectangleShapeImpl extends BaseToolWithRectangleShape { private final ToolType toolType; - BaseToolWithRectangleShapeImpl(ContextCallback contextCallback, - ToolOptionsVisibilityController toolOptionsViewController, ToolType toolType, ToolPaint toolPaint, Workspace layerModelWrapper, CommandManager commandManager) { + BaseToolWithRectangleShapeImpl(ContextCallback contextCallback, ToolOptionsViewController toolOptionsViewController, ToolType toolType, ToolPaint toolPaint, Workspace layerModelWrapper, CommandManager commandManager) { super(contextCallback, toolOptionsViewController, toolPaint, layerModelWrapper, commandManager); this.toolType = toolType; } diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/BrushToolTest.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/BrushToolTest.java index 53ddc5bf72..6e6331aac7 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/BrushToolTest.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/BrushToolTest.java @@ -37,7 +37,7 @@ import org.catrobat.paintroid.tools.common.ConstantsKt; import org.catrobat.paintroid.tools.implementation.BrushTool; import org.catrobat.paintroid.tools.options.BrushToolOptionsView; -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController; +import org.catrobat.paintroid.tools.options.ToolOptionsViewController; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -68,7 +68,7 @@ public class BrushToolTest { @Mock private BrushToolOptionsView brushToolOptionsView; @Mock - private ToolOptionsVisibilityController toolOptionsViewController; + private ToolOptionsViewController toolOptionsViewController; @Mock private Workspace workspace; @Mock diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/CursorToolTest.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/CursorToolTest.java index 95a02919c0..536216affc 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/CursorToolTest.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/CursorToolTest.java @@ -35,7 +35,7 @@ import org.catrobat.paintroid.tools.common.ConstantsKt; import org.catrobat.paintroid.tools.implementation.CursorTool; import org.catrobat.paintroid.tools.options.BrushToolOptionsView; -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController; +import org.catrobat.paintroid.tools.options.ToolOptionsViewController; import org.catrobat.paintroid.ui.Perspective; import org.junit.Before; import org.junit.Test; @@ -68,7 +68,7 @@ public class CursorToolTest { @Mock private BrushToolOptionsView brushToolOptionsView; @Mock - private ToolOptionsVisibilityController toolOptionsViewController; + private ToolOptionsViewController toolOptionsViewController; @Mock private ContextCallback contextCallback; diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/FillToolTest.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/FillToolTest.java index c8832d1b80..a5fe2c0826 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/FillToolTest.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/FillToolTest.java @@ -28,7 +28,7 @@ import org.catrobat.paintroid.tools.Workspace; import org.catrobat.paintroid.tools.implementation.FillTool; import org.catrobat.paintroid.tools.options.FillToolOptionsView; -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController; +import org.catrobat.paintroid.tools.options.ToolOptionsViewController; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -44,7 +44,7 @@ public class FillToolTest { @Mock public ContextCallback contextCallback; @Mock - public ToolOptionsVisibilityController toolOptionsViewController; + public ToolOptionsViewController toolOptionsViewController; @Mock public Workspace workspace; @Mock diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/ImportToolTest.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/ImportToolTest.java index 622e0fb1e8..ff7131be4b 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/ImportToolTest.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/ImportToolTest.java @@ -27,7 +27,7 @@ import org.catrobat.paintroid.tools.ToolPaint; import org.catrobat.paintroid.tools.Workspace; import org.catrobat.paintroid.tools.implementation.ImportTool; -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController; +import org.catrobat.paintroid.tools.options.ToolOptionsViewController; import org.catrobat.paintroid.ui.Perspective; import org.junit.Before; import org.junit.Test; @@ -51,7 +51,7 @@ public class ImportToolTest { @Mock private ToolPaint toolPaint; @Mock - private ToolOptionsVisibilityController toolOptionsViewController; + private ToolOptionsViewController toolOptionsViewController; @Mock private ContextCallback contextCallback; @Mock diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/LineToolTest.kt b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/LineToolTest.kt index 53f5d61418..c687dc6339 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/LineToolTest.kt +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/LineToolTest.kt @@ -33,7 +33,7 @@ import org.catrobat.paintroid.tools.ToolPaint import org.catrobat.paintroid.tools.Workspace import org.catrobat.paintroid.tools.implementation.LineTool import org.catrobat.paintroid.tools.options.BrushToolOptionsView -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController import org.catrobat.paintroid.ui.Perspective import org.catrobat.paintroid.ui.viewholder.TopBarViewHolder import org.junit.Assert @@ -47,7 +47,7 @@ class LineToolTest { private val commandManager = Mockito.mock(CommandManager::class.java) private var workspace = Mockito.mock(Workspace::class.java) private val brushToolOptions = Mockito.mock(BrushToolOptionsView::class.java) - private val toolOptionsController = Mockito.mock(ToolOptionsVisibilityController::class.java) + private val toolOptionsViewController = Mockito.mock(ToolOptionsViewController::class.java) private val contextCallback = Mockito.mock(ContextCallback::class.java) private lateinit var tool: LineTool private var screenWidth = 1920 @@ -84,7 +84,7 @@ class LineToolTest { tool = LineTool( brushToolOptions, contextCallback, - toolOptionsController, + toolOptionsViewController, toolPaint, workspace, commandManager, diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/PipetteToolTest.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/PipetteToolTest.java index 999214398f..da51388021 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/PipetteToolTest.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/PipetteToolTest.java @@ -30,7 +30,7 @@ import org.catrobat.paintroid.tools.ToolType; import org.catrobat.paintroid.tools.Workspace; import org.catrobat.paintroid.tools.implementation.PipetteTool; -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController; +import org.catrobat.paintroid.tools.options.ToolOptionsViewController; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -64,7 +64,7 @@ public class PipetteToolTest { @Mock private Workspace workspace; @Mock - private ToolOptionsVisibilityController toolOptionsViewController; + private ToolOptionsViewController toolOptionsViewController; @Mock private ContextCallback contextCallback; diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/ShapeToolTest.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/ShapeToolTest.java index d0406868cb..9c5151bfac 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/ShapeToolTest.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/ShapeToolTest.java @@ -29,7 +29,7 @@ import org.catrobat.paintroid.tools.drawable.DrawableShape; import org.catrobat.paintroid.tools.implementation.ShapeTool; import org.catrobat.paintroid.tools.options.ShapeToolOptionsView; -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController; +import org.catrobat.paintroid.tools.options.ToolOptionsViewController; import org.catrobat.paintroid.ui.Perspective; import org.junit.Before; import org.junit.Rule; @@ -58,7 +58,7 @@ public class ShapeToolTest { @Mock private ShapeToolOptionsView shapeToolOptions; @Mock - private ToolOptionsVisibilityController toolOptionsViewController; + private ToolOptionsViewController toolOptionsViewController; @Mock private ContextCallback contextCallback; @Mock diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/SprayToolTest.kt b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/SprayToolTest.kt index f1f25c1bac..754d7a4a6e 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/SprayToolTest.kt +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/SprayToolTest.kt @@ -33,7 +33,7 @@ import org.catrobat.paintroid.tools.Workspace import org.catrobat.paintroid.tools.implementation.STROKE_25 import org.catrobat.paintroid.tools.implementation.SprayTool import org.catrobat.paintroid.tools.options.SprayToolOptionsView -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController import org.junit.After import org.junit.Assert import org.junit.Before @@ -48,7 +48,7 @@ class SprayToolTest { private val workspace = Mockito.mock(Workspace::class.java) private val sprayToolOptionsView = Mockito.mock(SprayToolOptionsView::class.java) private val toolOptionsViewController = - Mockito.mock(ToolOptionsVisibilityController::class.java) + Mockito.mock(ToolOptionsViewController::class.java) private val contextCallback = Mockito.mock(ContextCallback::class.java) private lateinit var tool: SprayTool diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/StampToolTest.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/StampToolTest.java index 58f5c7d6ed..6141ac843c 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/StampToolTest.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/StampToolTest.java @@ -33,7 +33,7 @@ import org.catrobat.paintroid.tools.Workspace; import org.catrobat.paintroid.tools.implementation.StampTool; import org.catrobat.paintroid.tools.options.StampToolOptionsView; -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController; +import org.catrobat.paintroid.tools.options.ToolOptionsViewController; import org.catrobat.paintroid.ui.Perspective; import org.junit.Before; import org.junit.Test; @@ -60,7 +60,7 @@ public class StampToolTest { @Mock private StampToolOptionsView stampToolOptions; @Mock - private ToolOptionsVisibilityController toolOptionsViewController; + private ToolOptionsViewController toolOptionsViewController; @Mock private ContextCallback contextCallback; @Mock diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BaseTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BaseTool.kt index f07596495c..ff3b875d53 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BaseTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BaseTool.kt @@ -35,13 +35,13 @@ import org.catrobat.paintroid.tools.ToolPaint import org.catrobat.paintroid.tools.Workspace import org.catrobat.paintroid.tools.common.PointScrollBehavior import org.catrobat.paintroid.tools.common.ScrollBehavior -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController abstract class BaseTool( @JvmField open var contextCallback: ContextCallback, @JvmField - protected var toolOptionsViewController: ToolOptionsVisibilityController, + protected var toolOptionsViewController: ToolOptionsViewController, @JvmField protected var toolPaint: ToolPaint, @JvmField diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BaseToolWithRectangleShape.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BaseToolWithRectangleShape.kt index e83981c171..2bb536f0e0 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BaseToolWithRectangleShape.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BaseToolWithRectangleShape.kt @@ -40,7 +40,7 @@ import org.catrobat.paintroid.tools.ContextCallback import org.catrobat.paintroid.tools.ContextCallback.ScreenOrientation import org.catrobat.paintroid.tools.ToolPaint import org.catrobat.paintroid.tools.Workspace -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController import java.lang.Math.toDegrees import java.lang.Math.toRadians import kotlin.math.PI @@ -86,7 +86,7 @@ private const val BUNDLE_BOX_ROTATION = "BOX_ROTATION" abstract class BaseToolWithRectangleShape( contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager @@ -150,6 +150,9 @@ abstract class BaseToolWithRectangleShape( @JvmField var rectangleShrinkingOnHighlight: Int + @JvmField + var shouldDrawRectangle = true + private var boxResizeMargin: Float? = 0f private var rotationSymbolWidth: Float? = 0f private var currentAction: FloatingBoxAction? = null @@ -328,7 +331,9 @@ abstract class BaseToolWithRectangleShape( if (overlayDrawable != null) { drawOverlayDrawable(canvas, boxWidth, boxHeight, boxRotation) } - drawRectangle(canvas, boxWidth, boxHeight) + if (shouldDrawRectangle) { + drawRectangle(canvas, boxWidth, boxHeight) + } drawToolSpecifics(canvas, boxWidth, boxHeight) canvas.restore() } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BaseToolWithShape.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BaseToolWithShape.kt index f04fb4141b..21b692c380 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BaseToolWithShape.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BaseToolWithShape.kt @@ -31,7 +31,7 @@ import org.catrobat.paintroid.command.CommandManager import org.catrobat.paintroid.tools.ContextCallback import org.catrobat.paintroid.tools.ToolPaint import org.catrobat.paintroid.tools.Workspace -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController import kotlin.math.max import kotlin.math.min @@ -40,7 +40,7 @@ private const val BUNDLE_TOOL_POSITION_X = "TOOL_POSITION_X" abstract class BaseToolWithShape @SuppressLint("VisibleForTests") constructor( contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BrushTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BrushTool.kt index 382ac2d1dc..8bd9dd7a00 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BrushTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BrushTool.kt @@ -36,7 +36,7 @@ import org.catrobat.paintroid.tools.helper.AdvancedSettingsAlgorithms import org.catrobat.paintroid.tools.helper.AdvancedSettingsAlgorithms.smoothing import org.catrobat.paintroid.tools.helper.AdvancedSettingsAlgorithms.threshold import org.catrobat.paintroid.tools.options.BrushToolOptionsView -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController import kotlin.math.abs import kotlin.math.max import kotlin.math.sqrt @@ -44,7 +44,7 @@ import kotlin.math.sqrt open class BrushTool( val brushToolOptionsView: BrushToolOptionsView, contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/CursorTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/CursorTool.kt index 00e5453db8..8b54948125 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/CursorTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/CursorTool.kt @@ -40,7 +40,7 @@ import org.catrobat.paintroid.tools.helper.AdvancedSettingsAlgorithms.smoothing import org.catrobat.paintroid.tools.helper.AdvancedSettingsAlgorithms.smoothingAlgorithm import org.catrobat.paintroid.tools.helper.AdvancedSettingsAlgorithms.threshold import org.catrobat.paintroid.tools.options.BrushToolOptionsView -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController import kotlin.math.abs import kotlin.math.max import kotlin.math.min @@ -54,7 +54,7 @@ private const val CURSOR_LINES = 4 open class CursorTool( private val brushToolOptionsView: BrushToolOptionsView, contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/EraserTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/EraserTool.kt index d654bfd9c1..1607511f8d 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/EraserTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/EraserTool.kt @@ -26,12 +26,12 @@ import org.catrobat.paintroid.tools.ToolPaint import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.Workspace import org.catrobat.paintroid.tools.options.BrushToolOptionsView -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController class EraserTool( brushToolOptionsView: BrushToolOptionsView, contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/FillTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/FillTool.kt index 4b369affbd..500a981ad7 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/FillTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/FillTool.kt @@ -27,7 +27,7 @@ import org.catrobat.paintroid.tools.ToolPaint import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.Workspace import org.catrobat.paintroid.tools.options.FillToolOptionsView -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController private const val HUNDRED = 100f const val DEFAULT_TOLERANCE_IN_PERCENT = 12 @@ -36,7 +36,7 @@ const val MAX_ABSOLUTE_TOLERANCE = 510 class FillTool( fillToolOptionsView: FillToolOptionsView, contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt index ca7a010476..4a60c3f41b 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt @@ -26,7 +26,7 @@ import org.catrobat.paintroid.tools.ContextCallback import org.catrobat.paintroid.tools.ToolPaint import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.Workspace -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController import kotlin.math.max import kotlin.math.min @@ -34,7 +34,7 @@ private const val BUNDLE_TOOL_DRAWING_BITMAP = "BUNDLE_TOOL_DRAWING_BITMAP" class ImportTool( contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/LineTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/LineTool.kt index ecb9c904a0..83d1a35872 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/LineTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/LineTool.kt @@ -33,13 +33,13 @@ import org.catrobat.paintroid.tools.Workspace import org.catrobat.paintroid.tools.common.CommonBrushChangedListener import org.catrobat.paintroid.tools.common.CommonBrushPreviewListener import org.catrobat.paintroid.tools.options.BrushToolOptionsView -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController import org.catrobat.paintroid.ui.viewholder.TopBarViewHolder class LineTool( private val brushToolOptionsView: BrushToolOptionsView, contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PipetteTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PipetteTool.kt index a29c5c004d..5ec739f5fd 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PipetteTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PipetteTool.kt @@ -27,11 +27,11 @@ import org.catrobat.paintroid.tools.ContextCallback import org.catrobat.paintroid.tools.ToolPaint import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.Workspace -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController class PipetteTool( contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt index 47dc68d12d..4c28646229 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt @@ -32,7 +32,7 @@ import org.catrobat.paintroid.tools.drawable.DrawableShape import org.catrobat.paintroid.tools.drawable.DrawableStyle import org.catrobat.paintroid.tools.helper.toPoint import org.catrobat.paintroid.tools.options.ShapeToolOptionsView -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController private const val SHAPE_OFFSET = 10f private const val DEFAULT_OUTLINE_WIDTH = 25 @@ -43,7 +43,7 @@ private const val BUNDLE_OUTLINE_WIDTH = "OUTLINE_WIDTH" class ShapeTool( shapeToolOptionsView: ShapeToolOptionsView, contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SprayTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SprayTool.kt index 8925f84bc7..e79a9e0069 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SprayTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SprayTool.kt @@ -35,7 +35,7 @@ import org.catrobat.paintroid.tools.ToolPaint import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.Workspace import org.catrobat.paintroid.tools.options.SprayToolOptionsView -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController import java.util.concurrent.ConcurrentLinkedQueue import kotlin.math.cos import kotlin.math.pow @@ -50,7 +50,7 @@ private const val CONSTANT_1 = 0.5f class SprayTool( var stampToolOptionsView: SprayToolOptionsView, override var contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt index 0ff027cad4..dcac608fd3 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt @@ -29,7 +29,7 @@ import org.catrobat.paintroid.tools.ToolPaint import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.Workspace import org.catrobat.paintroid.tools.options.StampToolOptionsView -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController private const val BUNDLE_TOOL_READY_FOR_PASTE = "BUNDLE_TOOL_READY_FOR_PASTE" private const val BUNDLE_TOOL_DRAWING_BITMAP = "BUNDLE_TOOL_DRAWING_BITMAP" @@ -37,7 +37,7 @@ private const val BUNDLE_TOOL_DRAWING_BITMAP = "BUNDLE_TOOL_DRAWING_BITMAP" class StampTool( stampToolOptionsView: StampToolOptionsView, contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt index b2c48804eb..68aad3663b 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt @@ -34,6 +34,7 @@ import org.catrobat.paintroid.tools.ToolPaint import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.Workspace import org.catrobat.paintroid.tools.options.TextToolOptionsView +import org.catrobat.paintroid.tools.options.ToolOptionsViewController import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController import kotlin.Exception import kotlin.math.max @@ -63,7 +64,7 @@ private const val TAG = "Can't set custom font" class TextTool( private val textToolOptionsView: TextToolOptionsView, contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager, 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 6adcbb8af5..df22a027a5 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 @@ -19,6 +19,8 @@ package org.catrobat.paintroid.tools.implementation import android.graphics.Canvas +import android.graphics.Color +import android.graphics.Paint import android.graphics.PointF import android.graphics.RectF import androidx.annotation.VisibleForTesting @@ -37,10 +39,12 @@ import org.catrobat.paintroid.tools.Workspace import org.catrobat.paintroid.tools.helper.CropAlgorithm import org.catrobat.paintroid.tools.helper.DefaultNumberRangeFilter import org.catrobat.paintroid.tools.helper.JavaCropAlgorithm +import org.catrobat.paintroid.tools.options.ToolOptionsViewController import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController import org.catrobat.paintroid.tools.options.TransformToolOptionsView import org.catrobat.paintroid.ui.tools.NumberRangeFilter import kotlin.math.floor +import kotlin.math.max import kotlin.math.min @VisibleForTesting @@ -54,11 +58,15 @@ private const val ROTATION_ENABLED = false private const val RESIZE_POINTS_VISIBLE = false private const val RESPECT_MAXIMUM_BORDER_RATIO = false private const val RESPECT_MAXIMUM_BOX_RESOLUTION = true +private const val DEFAULT_CURSOR_STROKE_WIDTH = 5f +private const val MINIMAL_CURSOR_STROKE_WIDTH = 1f +private const val MAXIMAL_CURSOR_STROKE_WIDTH = 10f +private const val CURSOR_LINES = 4 class TransformTool( private val transformToolOptionsView: TransformToolOptionsView, contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager, @@ -89,6 +97,7 @@ class TransformTool( private var cropRunFinished = false private var maxImageResolutionInformationAlreadyShown = false private var zeroSizeBitmap = false + private var isSetCenter = false private val rangeFilterHeight: NumberRangeFilter private val rangeFilterWidth: NumberRangeFilter private val cropAlgorithm: CropAlgorithm @@ -112,7 +121,12 @@ class TransformTool( initResizeBounds() toolOptionsViewController.setCallback(object : ToolOptionsVisibilityController.Callback { override fun onHide() { - if (!zeroSizeBitmap) { + if (isSetCenter) { + contextCallback.showNotificationWithDuration( + R.string.set_center_info_text, + ContextCallback.NotificationDuration.LONG + ) + } else if (!zeroSizeBitmap) { contextCallback.showNotificationWithDuration( R.string.transform_info_text, ContextCallback.NotificationDuration.LONG @@ -131,6 +145,10 @@ class TransformTool( autoCrop() } + override fun setCenterClicked() { + setCenter() + } + override fun rotateCounterClockwiseClicked() { rotateCounterClockWise() } @@ -176,11 +194,19 @@ class TransformTool( } override fun drawToolSpecifics(canvas: Canvas, boxWidth: Float, boxHeight: Float) { + + if (isSetCenter) { + drawCursor(canvas) + return + } + var width = boxWidth var height = boxHeight + if (cropRunFinished) { linePaint.color = primaryShapeColor linePaint.strokeWidth = toolStrokeWidth * 2 + val rightTopPoint = PointF(-width / 2, -height / 2) repeat(SIDES) { val resizeLineLengthHeight = height / CONSTANT_1 @@ -326,6 +352,111 @@ class TransformTool( } } + private fun setCenter() { + CoroutineScope(Dispatchers.Default).launch { + isSetCenter = true + shouldDrawRectangle = false + withContext(Dispatchers.Main) { + toolOptionsViewController.hide() + } + workspace.invalidate() + } + } + + private fun drawCursor(canvas: Canvas) { + val positionX = 0.0f + val positionY = 0.0f + val brushStrokeWidth = max(toolPaint.strokeWidth / 2f, 1f) + val strokeWidth = getStrokeWidthForZoom( + DEFAULT_CURSOR_STROKE_WIDTH, + MINIMAL_CURSOR_STROKE_WIDTH, MAXIMAL_CURSOR_STROKE_WIDTH + ) + val cursorPartLength = strokeWidth * 2 + val innerCircleRadius = brushStrokeWidth + strokeWidth / 2f + val outerCircleRadius = innerCircleRadius + strokeWidth + linePaint.apply { + color = + contextCallback.getColor(R.color.pocketpaint_main_cursor_tool_inactive_primary_color) + style = Paint.Style.STROKE + this.strokeWidth = strokeWidth + } + drawCursorCircle( + canvas, + strokeWidth, + outerCircleRadius, + innerCircleRadius, + positionX, + positionY + ) + + linePaint.style = Paint.Style.FILL + var startLineLengthAddition = strokeWidth / 2f + var endLineLengthAddition = cursorPartLength + strokeWidth + var lineNr = 0 + while (lineNr < CURSOR_LINES) { + if (lineNr % 2 == 0) { + linePaint.color = Color.LTGRAY + } else { + linePaint.color = + contextCallback.getColor(R.color.pocketpaint_main_cursor_tool_inactive_primary_color) + } + + canvas.drawLine( + positionX - outerCircleRadius - startLineLengthAddition, + positionY, + positionX - outerCircleRadius - endLineLengthAddition, + positionY, + linePaint + ) + canvas.drawLine( + positionX + outerCircleRadius + startLineLengthAddition, + positionY, + positionX + outerCircleRadius + endLineLengthAddition, + positionY, + linePaint + ) + canvas.drawLine( + positionX, + positionY + outerCircleRadius + startLineLengthAddition, + positionX, + positionY + outerCircleRadius + endLineLengthAddition, + linePaint + ) + canvas.drawLine( + positionX, + positionY - outerCircleRadius - startLineLengthAddition, + positionX, + positionY - outerCircleRadius - endLineLengthAddition, + linePaint + ) + lineNr++ + startLineLengthAddition = strokeWidth / 2f + cursorPartLength * lineNr + endLineLengthAddition = strokeWidth + cursorPartLength * (lineNr + 1f) + } + linePaint.style = Paint.Style.STROKE + } + + private fun drawCursorCircle( + canvas: Canvas, + strokeWidth: Float, + outerCircleRadius: Float, + innerCircleRadius: Float, + positionX: Float, + positionY: Float, + ) { + canvas.drawCircle(positionX, positionY, outerCircleRadius, linePaint) + linePaint.color = Color.LTGRAY + canvas.drawCircle(positionX, positionY, innerCircleRadius, linePaint) + linePaint.color = Color.TRANSPARENT + linePaint.style = Paint.Style.FILL + canvas.drawCircle( + positionX, + positionY, + innerCircleRadius - strokeWidth / 2f, + linePaint + ) + } + private fun areResizeBordersValid(): Boolean { if (resizeBoundWidthXRight < resizeBoundWidthXLeft || resizeBoundHeightYTop > resizeBoundHeightYBottom @@ -362,6 +493,12 @@ class TransformTool( override fun onClickOnButton() { executeResizeCommand() + + if (isSetCenter) { + isSetCenter = false + shouldDrawRectangle = true + workspace.invalidate() + } } override fun preventThatBoxGetsTooLarge( diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/WatercolorTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/WatercolorTool.kt index 3023fde6d9..816b62746c 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/WatercolorTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/WatercolorTool.kt @@ -25,7 +25,7 @@ import org.catrobat.paintroid.tools.ToolPaint import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.Workspace import org.catrobat.paintroid.tools.options.BrushToolOptionsView -import org.catrobat.paintroid.tools.options.ToolOptionsVisibilityController +import org.catrobat.paintroid.tools.options.ToolOptionsViewController private const val MAX_ALPHA_VALUE = 255 private const val MAX_NEW_RANGE = 150 @@ -34,7 +34,7 @@ private const val MIN_NEW_RANGE = 20 class WatercolorTool( brushToolOptionsView: BrushToolOptionsView, contextCallback: ContextCallback, - toolOptionsViewController: ToolOptionsVisibilityController, + toolOptionsViewController: ToolOptionsViewController, toolPaint: ToolPaint, workspace: Workspace, commandManager: CommandManager, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/options/TransformToolOptionsView.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/options/TransformToolOptionsView.kt index 74c553e7d7..54a8d9d411 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/options/TransformToolOptionsView.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/options/TransformToolOptionsView.kt @@ -34,6 +34,8 @@ interface TransformToolOptionsView { interface Callback { fun autoCropClicked() + fun setCenterClicked() + fun rotateCounterClockwiseClicked() fun rotateClockwiseClicked() diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/tools/DefaultTransformToolOptionsView.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/tools/DefaultTransformToolOptionsView.kt index 9971e04293..5ea52028c6 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/tools/DefaultTransformToolOptionsView.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/tools/DefaultTransformToolOptionsView.kt @@ -74,6 +74,10 @@ class DefaultTransformToolOptionsView(rootView: ViewGroup) : TransformToolOption .setOnClickListener { callback?.autoCropClicked() } + optionsView.findViewById(R.id.pocketpaint_transform_set_center_btn) + .setOnClickListener { + callback?.setCenterClicked() + } optionsView.findViewById(R.id.pocketpaint_transform_rotate_left_btn) .setOnClickListener { callback?.rotateCounterClockwiseClicked() diff --git a/Paintroid/src/main/res/drawable/ic_pocketpaint_tool_center_focus_strong.xml b/Paintroid/src/main/res/drawable/ic_pocketpaint_tool_center_focus_strong.xml new file mode 100644 index 0000000000..04da4972b9 --- /dev/null +++ b/Paintroid/src/main/res/drawable/ic_pocketpaint_tool_center_focus_strong.xml @@ -0,0 +1,12 @@ + + + + diff --git a/Paintroid/src/main/res/layout/dialog_pocketpaint_transform_tool.xml b/Paintroid/src/main/res/layout/dialog_pocketpaint_transform_tool.xml index f9abe5c9f0..9590c61830 100644 --- a/Paintroid/src/main/res/layout/dialog_pocketpaint_transform_tool.xml +++ b/Paintroid/src/main/res/layout/dialog_pocketpaint_transform_tool.xml @@ -37,19 +37,9 @@ -