Skip to content

Commit 401d3a3

Browse files
committed
PAINTROID-396 Multiline tool with movable intermediate points
CR
1 parent 9daa735 commit 401d3a3

File tree

8 files changed

+77
-99
lines changed

8 files changed

+77
-99
lines changed

Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/tools/DynamicLineToolIntegrationTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ class DynamicLineToolIntegrationTest {
886886
val currentTool = launchActivityRule.activity.defaultToolController.currentTool as DynamicLineTool
887887
Assert.assertEquals(7, currentTool.vertexStack.size)
888888

889-
var uriFile = saveImage()
889+
val uriFile = saveImage()
890890

891891
newImage()
892892
Assert.assertEquals(0, currentTool.vertexStack.size)
@@ -898,7 +898,7 @@ class DynamicLineToolIntegrationTest {
898898
}
899899

900900
private fun loadImage(uriFile: Uri) {
901-
var fileContent = CommandSerializer(activity, activity.commandManager, activity.model).readFromFile(uriFile!!)
901+
val fileContent = CommandSerializer(activity, activity.commandManager, activity.model).readFromFile(uriFile!!)
902902
for (command in fileContent.commandModel.commands) {
903903
activity.commandManager.addCommand(command)
904904
}

Paintroid/src/androidTest/java/org/catrobat/paintroid/test/junit/tools/DynamicLineToolTest.kt

+27-27
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class DynamicLineToolTest {
114114
fun testTwoVerticesCreatedAfterFirstClick() {
115115
Assert.assertEquals(0, tool.vertexStack.size)
116116

117-
var firstClickCoordinate = PointF(5f, 5f)
117+
val firstClickCoordinate = PointF(5f, 5f)
118118
tool.handleDown(firstClickCoordinate)
119119
tool.handleUp(firstClickCoordinate)
120120

@@ -124,18 +124,18 @@ class DynamicLineToolTest {
124124
@Test
125125
@UiThreadTest
126126
fun testLastVertexCenterChangesAfterClick() {
127-
var firstClickCoordinate = PointF(5f, 5f)
127+
val firstClickCoordinate = PointF(5f, 5f)
128128
tool.handleDown(firstClickCoordinate)
129129
tool.handleUp(firstClickCoordinate)
130130

131-
var secondClickCoordinate = PointF(100f, 100f)
131+
val secondClickCoordinate = PointF(100f, 100f)
132132
tool.handleDown(secondClickCoordinate)
133133
tool.handleUp(secondClickCoordinate)
134134

135135
Assert.assertEquals(2, tool.vertexStack.size)
136136
Assert.assertEquals(secondClickCoordinate, tool.vertexStack.last.vertexCenter)
137137

138-
var thirdClickCoordinate = PointF(200f, 200f)
138+
val thirdClickCoordinate = PointF(200f, 200f)
139139
tool.handleDown(thirdClickCoordinate)
140140
tool.handleUp(thirdClickCoordinate)
141141

@@ -146,11 +146,11 @@ class DynamicLineToolTest {
146146
@Test
147147
@UiThreadTest
148148
fun testLastVertexCenterChangesAfterMove() {
149-
var firstClickCoordinate = PointF(5f, 5f)
149+
val firstClickCoordinate = PointF(5f, 5f)
150150
tool.handleDown(firstClickCoordinate)
151151
tool.handleUp(firstClickCoordinate)
152152

153-
var secondClickCoordinate = PointF(100f, 100f)
153+
val secondClickCoordinate = PointF(100f, 100f)
154154
tool.handleDown(secondClickCoordinate)
155155
tool.handleUp(secondClickCoordinate)
156156

@@ -159,7 +159,7 @@ class DynamicLineToolTest {
159159

160160
tool.handleDown(secondClickCoordinate)
161161

162-
var movingCoordinate = PointF(200f, 200f)
162+
val movingCoordinate = PointF(200f, 200f)
163163
tool.handleMove(movingCoordinate)
164164
tool.handleUp(movingCoordinate)
165165

@@ -170,11 +170,11 @@ class DynamicLineToolTest {
170170
@Test
171171
@UiThreadTest
172172
fun testFirstVertexCenterChangesAfterMove() {
173-
var firstClickCoordinate = PointF(5f, 5f)
173+
val firstClickCoordinate = PointF(5f, 5f)
174174
tool.handleDown(firstClickCoordinate)
175175
tool.handleUp(firstClickCoordinate)
176176

177-
var secondClickCoordinate = PointF(100f, 100f)
177+
val secondClickCoordinate = PointF(100f, 100f)
178178
tool.handleDown(secondClickCoordinate)
179179
tool.handleUp(secondClickCoordinate)
180180

@@ -183,7 +183,7 @@ class DynamicLineToolTest {
183183

184184
tool.handleDown(firstClickCoordinate)
185185

186-
var movingCoordinate = PointF(200f, 200f)
186+
val movingCoordinate = PointF(200f, 200f)
187187
tool.handleMove(movingCoordinate)
188188
tool.handleUp(movingCoordinate)
189189

@@ -197,8 +197,8 @@ class DynamicLineToolTest {
197197
var plusButtonVisibility = DynamicLineTool.topBarViewHolder?.plusButton?.visibility
198198
Assert.assertEquals(plusButtonVisibility, View.GONE)
199199

200-
var tapDownCoordinate = PointF(5f, 5f)
201-
var tapUpCoordinate = PointF(10f, 10f)
200+
val tapDownCoordinate = PointF(5f, 5f)
201+
val tapUpCoordinate = PointF(10f, 10f)
202202
tool.handleDown(tapDownCoordinate)
203203
tool.handleUp(tapUpCoordinate)
204204

@@ -211,11 +211,11 @@ class DynamicLineToolTest {
211211
fun testAddPathIsSetAfterClickingPlus() {
212212
Assert.assertEquals(false, tool.addNewPath)
213213

214-
var firstClickCoordinate = PointF(5f, 5f)
214+
val firstClickCoordinate = PointF(5f, 5f)
215215
tool.handleDown(firstClickCoordinate)
216216
tool.handleUp(firstClickCoordinate)
217217

218-
var secondClickCoordinate = PointF(100f, 100f)
218+
val secondClickCoordinate = PointF(100f, 100f)
219219
tool.handleDown(secondClickCoordinate)
220220
tool.handleUp(secondClickCoordinate)
221221

@@ -229,17 +229,17 @@ class DynamicLineToolTest {
229229
fun testThreeVerticesCreatedAfterClickingPlus() {
230230
Assert.assertEquals(0, tool.vertexStack.size)
231231

232-
var firstClickCoordinate = PointF(5f, 5f)
232+
val firstClickCoordinate = PointF(5f, 5f)
233233
tool.handleDown(firstClickCoordinate)
234234
tool.handleUp(firstClickCoordinate)
235235

236-
var secondClickCoordinate = PointF(100f, 100f)
236+
val secondClickCoordinate = PointF(100f, 100f)
237237
tool.handleDown(secondClickCoordinate)
238238
tool.handleUp(secondClickCoordinate)
239239

240240
tool.onClickOnPlus()
241241

242-
var thirdClickCoordinate = PointF(200f, 200f)
242+
val thirdClickCoordinate = PointF(200f, 200f)
243243
tool.handleDown(thirdClickCoordinate)
244244
tool.handleUp(thirdClickCoordinate)
245245

@@ -252,8 +252,8 @@ class DynamicLineToolTest {
252252
var plusButtonVisibility = DynamicLineTool.topBarViewHolder?.plusButton?.visibility
253253
Assert.assertEquals(plusButtonVisibility, View.GONE)
254254

255-
var tapDownCoordinate = PointF(5f, 5f)
256-
var tapUpCoordinate = PointF(10f, 10f)
255+
val tapDownCoordinate = PointF(5f, 5f)
256+
val tapUpCoordinate = PointF(10f, 10f)
257257
tool.handleDown(tapDownCoordinate)
258258
tool.handleUp(tapUpCoordinate)
259259

@@ -315,8 +315,8 @@ class DynamicLineToolTest {
315315
fun testVertexStackIsClearedAfterCheckmark() {
316316
Assert.assertEquals(0, tool.vertexStack.size)
317317

318-
var tapDownCoordinate = PointF(5f, 5f)
319-
var tapUpCoordinate = PointF(10f, 10f)
318+
val tapDownCoordinate = PointF(5f, 5f)
319+
val tapUpCoordinate = PointF(10f, 10f)
320320
tool.handleDown(tapDownCoordinate)
321321
tool.handleUp(tapUpCoordinate)
322322

@@ -332,17 +332,17 @@ class DynamicLineToolTest {
332332
Assert.assertEquals(null, tool.movingVertex)
333333
Assert.assertEquals(null, tool.successorVertex)
334334

335-
var firstVertexCoordinate = PointF(5f, 5f)
335+
val firstVertexCoordinate = PointF(5f, 5f)
336336
tool.handleDown(firstVertexCoordinate)
337337
tool.handleUp(firstVertexCoordinate)
338338

339-
var middleVertexCoordinate = PointF(100f, 100f)
339+
val middleVertexCoordinate = PointF(100f, 100f)
340340
tool.handleDown(middleVertexCoordinate)
341341
tool.handleUp(middleVertexCoordinate)
342342

343343
tool.onClickOnPlus()
344344

345-
var lastVertexCoordinate = PointF(200f, 200f)
345+
val lastVertexCoordinate = PointF(200f, 200f)
346346
tool.handleDown(lastVertexCoordinate)
347347
tool.handleUp(lastVertexCoordinate)
348348

@@ -360,17 +360,17 @@ class DynamicLineToolTest {
360360
Assert.assertEquals(null, tool.movingVertex)
361361
Assert.assertEquals(null, tool.successorVertex)
362362

363-
var firstVertexCoordinate = PointF(5f, 5f)
363+
val firstVertexCoordinate = PointF(5f, 5f)
364364
tool.handleDown(firstVertexCoordinate)
365365
tool.handleUp(firstVertexCoordinate)
366366

367-
var middleVertexCoordinate = PointF(100f, 100f)
367+
val middleVertexCoordinate = PointF(100f, 100f)
368368
tool.handleDown(middleVertexCoordinate)
369369
tool.handleUp(middleVertexCoordinate)
370370

371371
tool.onClickOnPlus()
372372

373-
var lastVertexCoordinate = PointF(200f, 200f)
373+
val lastVertexCoordinate = PointF(200f, 200f)
374374
tool.handleDown(lastVertexCoordinate)
375375
tool.handleUp(lastVertexCoordinate)
376376

Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/DefaultCommandManager.kt

+2-26
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class DefaultCommandManager(
113113
val command = undoCommandList.pop()
114114

115115
if (command is DynamicPathCommand) {
116-
var switchedTool = handleUndoForDynamicLineTool(command)
116+
val switchedTool = handleUndoForDynamicLineTool(command)
117117
if (switchedTool) return
118118
}
119119
redoCommandList.addFirst(command)
@@ -126,7 +126,7 @@ class DefaultCommandManager(
126126

127127
private fun handleUndoForDynamicLineTool(command: DynamicPathCommand): Boolean {
128128
if (mainActivity == null) return false
129-
var currentTool = mainActivity.defaultToolController.currentTool
129+
val currentTool = mainActivity.defaultToolController.currentTool
130130
if (currentTool is DynamicLineTool && currentTool.vertexStack.isNotEmpty()) {
131131
currentTool.updateVertexStackAfterUndo()
132132
currentTool.setToolPaint(command)
@@ -255,23 +255,6 @@ class DefaultCommandManager(
255255
}
256256
}
257257

258-
// private fun handleRedoForDynamicLineTool(command: Command) {
259-
// var currentTool = mainActivity.defaultToolController.currentTool
260-
// if (currentTool is DynamicLineTool && command !is DynamicPathCommand) {
261-
// currentTool.clear()
262-
// }
263-
// if (command is DynamicPathCommand) {
264-
// if (currentTool !is DynamicLineTool) {
265-
// command.switchToDynamicLineTool(mainActivity)
266-
// }
267-
// while (mainActivity.defaultToolController.currentTool !is DynamicLineTool)
268-
// currentTool = mainActivity.defaultToolController.currentTool
269-
// if (command.isSourcePath) {
270-
// (currentTool as DynamicLineTool).clear()
271-
// }
272-
// (currentTool as DynamicLineTool).updateVertexStackAfterRedo(command)
273-
// }
274-
// }
275258
private fun handleRedoForDynamicLineTool(command: Command) {
276259
if (mainActivity == null) return
277260
var currentTool = mainActivity.defaultToolController.currentTool
@@ -314,13 +297,11 @@ class DefaultCommandManager(
314297

315298
override fun shutdown() = Unit
316299

317-
// LINETOOL_ONLY
318300
override fun undoIgnoringColorChanges() {
319301
addAndExecuteCommands(separateColorCommandsAndUndo())
320302
notifyCommandExecuted()
321303
}
322304

323-
// LINETOOL_ONLY
324305
override fun undoIgnoringColorChangesAndAddCommand(command: Command) {
325306
val colorCommandList = separateColorCommandsAndUndo()
326307
undoCommandList.addFirst(command)
@@ -330,7 +311,6 @@ class DefaultCommandManager(
330311
notifyCommandExecuted()
331312
}
332313

333-
// LINETOOL_ONLY
334314
private fun separateColorCommandsAndUndo(): Deque<Command> {
335315
val colorCommandList = removeColorCommands()
336316
if (undoCommandList.isNotEmpty() && undoCommandList.first != null) {
@@ -341,7 +321,6 @@ class DefaultCommandManager(
341321
return colorCommandList
342322
}
343323

344-
// LINETOOL_ONLY
345324
override fun undoInConnectedLinesMode() {
346325
val colorCommandList = removeColorCommands()
347326
if (undoCommandList.isNotEmpty()) {
@@ -364,7 +343,6 @@ class DefaultCommandManager(
364343
}
365344
}
366345

367-
// LINETOOL_ONLY
368346
private fun recolorLastLine(colorCommandList: Deque<Command>) {
369347
if (undoCommandList.isNotEmpty() && undoCommandList.first !is ColorChangedCommand) {
370348
val firstNonColorCommand = undoCommandList.pop()
@@ -401,7 +379,6 @@ class DefaultCommandManager(
401379
notifyCommandExecuted()
402380
}
403381

404-
// LINETOOL_ONLY
405382
override fun redoInConnectedLinesMode() {
406383
if (isRedoAvailable) {
407384
val command = redoCommandList.pop()
@@ -522,7 +499,6 @@ class DefaultCommandManager(
522499
}
523500
}
524501

525-
// LINETOOL_ONLY
526502
private fun removeColorCommands(): Deque<Command> {
527503
val colorCommandList: Deque<Command> = ArrayDeque()
528504
while (undoCommandList.isNotEmpty() && undoCommandList.first is ColorChangedCommand) {

Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/DynamicPathCommand.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class DynamicPathCommand(var paint: Paint, path: Path, startPoint: PointF, endPo
7474
mainActivity.runOnUiThread {
7575
mainActivity.presenter.switchToDynamicLineTool()
7676
if (mainActivity.defaultToolController.currentTool !is DynamicLineTool) return@runOnUiThread
77-
var tool = mainActivity.defaultToolController.currentTool as DynamicLineTool
77+
val tool = mainActivity.defaultToolController.currentTool as DynamicLineTool
7878
tool.createSourceAndDestinationVertices(
7979
dynamicPathCommands.first.startPoint,
8080
dynamicPathCommands.first.endPoint,

Paintroid/src/main/java/org/catrobat/paintroid/presenter/MainActivityPresenter.kt

-1
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,6 @@ open class MainActivityPresenter(
811811
override fun switchToDynamicLineTool() {
812812
if (toolController.toolType == ToolType.DYNAMICLINE) return
813813
idlingResource.increment()
814-
// bottomBarViewHolder.hide()
815814
checkForImplicitToolApplication()
816815
switchTool(ToolType.DYNAMICLINE)
817816
idlingResource.decrement()

0 commit comments

Comments
 (0)