Skip to content

Commit

Permalink
PAINTROID-291: color changes cannot be un/redone
Browse files Browse the repository at this point in the history
color changes weren't considered as commands and not added to CommandManager

* implemented a ColorChangedCommand

* ColorChangedCommand is added to CommandManager when color is selected in ColorPickerDialog

* adapted undo/redo behaviour in line tool to work with ColorCommands
  • Loading branch information
JulianJautz committed Mar 10, 2022
1 parent 6606246 commit 3dc10b5
Show file tree
Hide file tree
Showing 17 changed files with 592 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -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
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -43,9 +43,11 @@
import static org.catrobat.paintroid.test.espresso.util.UiInteractions.swipeAccurate;
import static org.catrobat.paintroid.test.espresso.util.UiInteractions.touchAt;
import static org.catrobat.paintroid.test.espresso.util.UiMatcher.withDrawable;
import static org.catrobat.paintroid.test.espresso.util.wrappers.ColorPickerViewInteraction.onColorPickerView;
import static org.catrobat.paintroid.test.espresso.util.wrappers.DrawingSurfaceInteraction.onDrawingSurfaceView;
import static org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction.onToolBarView;
import static org.catrobat.paintroid.test.espresso.util.wrappers.TopBarViewInteraction.onTopBarView;
import static org.catrobat.paintroid.test.utils.TestUtils.selectColorInDialog;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -324,4 +326,44 @@ public void testUndoRedoDoesNotResetLayerVisibility() {

DrawingSurfaceInteraction.onDrawingSurfaceView().checkPixelColor(Color.BLACK, BitmapLocationProvider.HALFWAY_LEFT_MIDDLE);
}

@Test
public void testChangeColorUndoRedo() {
selectColorInDialog(0);
selectColorInDialog(1);
selectColorInDialog(2);

onTopBarView().performUndo();
onTopBarView().performUndo();
onTopBarView().performUndo();
onColorPickerView()
.performOpenColorPicker();
onColorPickerView().checkCurrentViewColor(Color.BLACK);
onColorPickerView()
.onNegativeButton()
.perform(click());
onTopBarView().performRedo();
onTopBarView().performRedo();
onTopBarView().performRedo();

onDrawingSurfaceView().perform(swipeAccurate(DrawingSurfaceLocationProvider.HALFWAY_TOP_MIDDLE, DrawingSurfaceLocationProvider.HALFWAY_RIGHT_MIDDLE));

DrawingSurfaceInteraction.onDrawingSurfaceView().checkPixelColor(Color.parseColor("#FF078707"), BitmapLocationProvider.HALFWAY_TOP_MIDDLE);

onTopBarView().performUndo();
onTopBarView().performUndo();
onTopBarView().performUndo();

onDrawingSurfaceView().perform(swipeAccurate(DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_MIDDLE, DrawingSurfaceLocationProvider.HALFWAY_LEFT_MIDDLE));

DrawingSurfaceInteraction.onDrawingSurfaceView().checkPixelColor(Color.parseColor("#FF0074CD"), BitmapLocationProvider.HALFWAY_BOTTOM_MIDDLE);

onTopBarView().performUndo();
onTopBarView().performUndo();
onTopBarView().performRedo();

onDrawingSurfaceView().perform(swipeAccurate(DrawingSurfaceLocationProvider.HALFWAY_TOP_MIDDLE, DrawingSurfaceLocationProvider.HALFWAY_RIGHT_MIDDLE));

DrawingSurfaceInteraction.onDrawingSurfaceView().checkPixelColor(Color.parseColor("#FF0074CD"), BitmapLocationProvider.HALFWAY_TOP_MIDDLE);
}
}
Original file line number Diff line number Diff line change
@@ -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
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -44,6 +44,7 @@
import static org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction.onToolBarView;
import static org.catrobat.paintroid.test.espresso.util.wrappers.ToolPropertiesInteraction.onToolProperties;
import static org.catrobat.paintroid.test.espresso.util.wrappers.TopBarViewInteraction.onTopBarView;
import static org.catrobat.paintroid.test.utils.TestUtils.selectColorInDialog;
import static org.hamcrest.Matchers.allOf;

import static androidx.test.espresso.Espresso.onView;
Expand Down Expand Up @@ -485,4 +486,113 @@ public void testUndoWithDrawingConnectedLines() {

onTopBarView().performClickCheckmark();
}

@Test
public void testColorChangesInConnectedLineMode() {
onToolProperties().setColor(Color.BLACK);

onDrawingSurfaceView()
.perform(touchAt(DrawingSurfaceLocationProvider.HALFWAY_LEFT_MIDDLE));

onDrawingSurfaceView()
.perform(touchAt(DrawingSurfaceLocationProvider.HALFWAY_RIGHT_MIDDLE));

onTopBarView().performClickPlus();

onDrawingSurfaceView()
.perform(swipe(DrawingSurfaceLocationProvider.HALFWAY_TOP_LEFT, DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_RIGHT));

selectColorInDialog(0);

onDrawingSurfaceView()
.checkPixelColor(Color.parseColor("#FF0074CD"), BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT);

selectColorInDialog(1);

onDrawingSurfaceView()
.checkPixelColor(Color.parseColor("#FF00B4F1"), BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT);

onTopBarView().performUndo();

onDrawingSurfaceView()
.checkPixelColor(Color.parseColor("#FF0074CD"), BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT);

onTopBarView().performRedo();

onDrawingSurfaceView()
.checkPixelColor(Color.parseColor("#FF00B4F1"), BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT);

onTopBarView().performUndo();
onTopBarView().performUndo();
onTopBarView().performUndo();

onDrawingSurfaceView()
.checkPixelColor(Color.TRANSPARENT, BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT);

onTopBarView().performUndo();

onDrawingSurfaceView()
.checkPixelColor(Color.TRANSPARENT, BitmapLocationProvider.MIDDLE);

onTopBarView().performRedo();
onTopBarView().performRedo();
onTopBarView().performRedo();
onTopBarView().performRedo();

onDrawingSurfaceView()
.checkPixelColor(Color.parseColor("#FF0074CD"), BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT);

onTopBarView().performClickCheckmark();
}

@Test
public void testColorChangesAndQuittingConnectedLineMode() {
onToolProperties().setColor(Color.BLACK);

onDrawingSurfaceView()
.perform(touchAt(DrawingSurfaceLocationProvider.HALFWAY_LEFT_MIDDLE));

onDrawingSurfaceView()
.perform(touchAt(DrawingSurfaceLocationProvider.HALFWAY_RIGHT_MIDDLE));

onTopBarView().performClickPlus();

onDrawingSurfaceView()
.perform(swipe(DrawingSurfaceLocationProvider.HALFWAY_TOP_LEFT, DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_RIGHT));

selectColorInDialog(0);

onDrawingSurfaceView()
.checkPixelColor(Color.parseColor("#FF0074CD"), BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT);

selectColorInDialog(1);

selectColorInDialog(2);

onDrawingSurfaceView()
.checkPixelColor(Color.parseColor("#FF078707"), BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT);

onTopBarView().performUndo();
onTopBarView().performUndo();

onDrawingSurfaceView()
.checkPixelColor(Color.parseColor("#FF00B4F1"), BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT);

onDrawingSurfaceView()
.perform(touchAt(DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_LEFT));

onDrawingSurfaceView()
.checkPixelColor(Color.parseColor("#FF0074CD"), BitmapLocationProvider.HALFWAY_BOTTOM_LEFT);

onDrawingSurfaceView()
.checkPixelColor(Color.TRANSPARENT, BitmapLocationProvider.HALFWAY_BOTTOM_MIDDLE);

onDrawingSurfaceView()
.perform(touchAt(DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_RIGHT));

onDrawingSurfaceView()
.checkPixelColor(Color.parseColor("#FF0074CD"), BitmapLocationProvider.HALFWAY_BOTTOM_MIDDLE);

onTopBarView().performClickCheckmark();
}
}
Original file line number Diff line number Diff line change
@@ -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
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -20,11 +20,13 @@
package org.catrobat.paintroid.test.junit.command;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;

import org.catrobat.paintroid.command.Command;
import org.catrobat.paintroid.command.implementation.AddLayerCommand;
import org.catrobat.paintroid.command.implementation.ColorChangedCommand;
import org.catrobat.paintroid.command.implementation.CompositeCommand;
import org.catrobat.paintroid.command.implementation.CropCommand;
import org.catrobat.paintroid.command.implementation.DefaultCommandFactory;
Expand All @@ -36,8 +38,13 @@
import org.catrobat.paintroid.command.implementation.ResizeCommand;
import org.catrobat.paintroid.command.implementation.RotateCommand;
import org.catrobat.paintroid.command.implementation.SelectLayerCommand;
import org.catrobat.paintroid.contract.MainActivityContracts;
import org.catrobat.paintroid.tools.ToolReference;
import org.catrobat.paintroid.tools.implementation.DefaultToolReference;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.catrobat.paintroid.command.implementation.FlipCommand.FlipDirection.FLIP_HORIZONTAL;
import static org.catrobat.paintroid.command.implementation.RotateCommand.RotateDirection.ROTATE_LEFT;
Expand All @@ -49,6 +56,9 @@ public class DefaultCommandFactoryTest {

private DefaultCommandFactory commandFactory;

@Mock
private MainActivityContracts.BottomNavigationViewHolder bottomNavigationViewHolder;

@Before
public void setUp() {
commandFactory = new DefaultCommandFactory();
Expand Down Expand Up @@ -131,4 +141,12 @@ public void testCreateResizeCommand() {
Command command = commandFactory.createResizeCommand(10, 20);
assertThat(command, is(instanceOf(ResizeCommand.class)));
}

@Test
public void testCreateColorChangedCommand() {
ToolReference toolReference = new DefaultToolReference();
MockitoAnnotations.initMocks(this);
Command command = commandFactory.createColorChangedCommand(toolReference, bottomNavigationViewHolder, Color.WHITE);
assertThat(command, is(instanceOf(ColorChangedCommand.class)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Paintroid: An image manipulation application for Android.
* Copyright (C) 2010-2022 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.catrobat.paintroid.test.utils

import androidx.test.espresso.action.ViewActions
import org.catrobat.paintroid.test.espresso.util.wrappers.ColorPickerViewInteraction

class TestUtils private constructor() {
companion object {
@JvmStatic
fun selectColorInDialog(colorIdx: Int) {
ColorPickerViewInteraction.onColorPickerView()
.performOpenColorPicker()
ColorPickerViewInteraction.onColorPickerView()
.performClickColorPickerPresetSelectorButton(colorIdx)
ColorPickerViewInteraction.onColorPickerView()
.onPositiveButton()
.perform(ViewActions.click())
}
}
}
Original file line number Diff line number Diff line change
@@ -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
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -117,14 +117,15 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener {
@VisibleForTesting
lateinit var toolOptionsViewController: ToolOptionsViewController

lateinit var bottomNavigationViewHolder: BottomNavigationViewHolder

private lateinit var layerPresenter: LayerPresenter
private lateinit var drawingSurface: DrawingSurface
private lateinit var presenterMain: MainActivityContracts.Presenter
private lateinit var drawerLayoutViewHolder: DrawerLayoutViewHolder
private lateinit var keyboardListener: KeyboardListener
private lateinit var appFragment: PaintroidApplicationFragment
private lateinit var defaultToolController: DefaultToolController
private lateinit var bottomNavigationViewHolder: BottomNavigationViewHolder
private lateinit var commandFactory: CommandFactory
private var deferredRequestPermissionsResult: Runnable? = null
private lateinit var progressBar: ContentLoadingProgressBar
Expand Down
Original file line number Diff line number Diff line change
@@ -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
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -27,6 +27,8 @@ import org.catrobat.paintroid.command.implementation.FlipCommand.FlipDirection
import org.catrobat.paintroid.command.implementation.RotateCommand.RotateDirection
import org.catrobat.paintroid.command.serialization.SerializablePath
import org.catrobat.paintroid.command.serialization.SerializableTypeface
import org.catrobat.paintroid.contract.MainActivityContracts
import org.catrobat.paintroid.tools.ToolReference
import org.catrobat.paintroid.tools.drawable.ShapeDrawable

interface CommandFactory {
Expand Down Expand Up @@ -103,4 +105,6 @@ interface CommandFactory {
boxHeight: Float,
boxRotation: Float
): Command

fun createColorChangedCommand(toolReference: ToolReference, viewHolder: MainActivityContracts.BottomNavigationViewHolder, color: Int): Command
}
Original file line number Diff line number Diff line change
@@ -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
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -44,6 +44,14 @@ interface CommandManager {

fun shutdown()

fun undoIgnoringColorChanges()

fun undoIgnoringColorChangesAndAddCommand(command: Command)

fun undoInConnectedLinesMode()

fun redoInConnectedLinesMode()

interface CommandListener {
fun commandPostExecute()
}
Expand Down
Loading

0 comments on commit 3dc10b5

Please sign in to comment.