Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAINTROID-291: Color changes cannot be undone or redone #1044

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -19,12 +19,15 @@

package org.catrobat.paintroid.test.junit.command;

import android.content.Context;
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 +39,12 @@
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.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 Context context;

@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, context, 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
Expand Up @@ -126,14 +126,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 @@ -18,6 +18,7 @@
*/
package org.catrobat.paintroid.command

import android.content.Context
import android.graphics.Bitmap
import android.graphics.Paint
import android.graphics.Point
Expand All @@ -27,6 +28,7 @@ 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.tools.ToolReference
import org.catrobat.paintroid.tools.drawable.ShapeDrawable

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

fun createColorChangedCommand(toolReference: ToolReference, context: Context, 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,16 @@ interface CommandManager {

fun shutdown()

fun undoIgnoringColorChanges()

fun undoIgnoringColorChangesAndAddCommand(command: Command)

fun undoInConnectedLinesMode()

fun redoInConnectedLinesMode()

fun getCommandManagerModelForCatrobatImage(): CommandManagerModel?

interface CommandListener {
fun commandPostExecute()
}
Expand Down
Loading