Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Catrobat/Paintroid into …
Browse files Browse the repository at this point in the history
…PAINTROID-291_undo_for_color_changes

� Conflicts:
�	Paintroid/src/main/java/org/catrobat/paintroid/command/implementation/DefaultCommandManager.kt
�	Paintroid/src/main/java/org/catrobat/paintroid/presenter/LayerPresenter.kt
�	Paintroid/src/main/res/values-uk-rUA/string.xml
�	build.gradle
  • Loading branch information
Julian Raphael Jautz committed May 16, 2022
2 parents 60a0a37 + d9bffb1 commit 4230a3e
Show file tree
Hide file tree
Showing 105 changed files with 3,004 additions and 650 deletions.
16 changes: 0 additions & 16 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.catrobat.paintroid.test.espresso
import android.app.Activity
import android.app.Instrumentation.ActivityResult
import android.content.Intent
import android.content.pm.ActivityInfo
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
Expand Down Expand Up @@ -74,10 +75,12 @@ class LayerIntegrationTest {

private var bitmapHeight = 0
private var bitmapWidth = 0
private lateinit var activity: Activity
private lateinit var deletionFileList: ArrayList<File?>

@Before
fun setUp() {
activity = launchActivityRule.activity
deletionFileList = ArrayList()
val workspace = launchActivityRule.activity.workspace
bitmapHeight = workspace.height
Expand Down Expand Up @@ -540,6 +543,22 @@ class LayerIntegrationTest {
.checkMatchesColorResource(R.color.pocketpaint_color_picker_green1)
}

@Test
fun testLayerPreviewKeepsBitmapAfterOrientationChange() {
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.FILL)
DrawingSurfaceInteraction.onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.MIDDLE))
LayerMenuViewInteraction.onLayerMenuView()
.performOpen()
.checkLayerAtPositionHasTopLeftPixelWithColor(0, Color.BLACK)

activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE

LayerMenuViewInteraction.onLayerMenuView()
.checkLayerAtPositionHasTopLeftPixelWithColor(0, Color.BLACK)
}

@Test
fun testUndoRedoLayerRotate() {
ToolBarViewInteraction.onToolBarView()
Expand Down Expand Up @@ -623,8 +642,10 @@ class LayerIntegrationTest {
.performAddLayer()
.checkLayerCount(2)
.performToggleLayerVisibility(0)
.performLongClickLayer(0)
onView(withText(R.string.no_longclick_on_hidden_layer)).inRoot(RootMatchers.withDecorView(Matchers.not(launchActivityRule.activity.window.decorView))).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.performStartDragging(0)
onView(withText(R.string.no_longclick_on_hidden_layer))
.inRoot(RootMatchers.withDecorView(Matchers.not(launchActivityRule.activity.window.decorView)))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ public void testTabsAreSelectable() {
}

@Test
public void dontShowAlphaSliderFromCatrobat() {
public void dontShowAlphaRelatedStuffFromCatroidFormulaEditor() {
launchActivityRule.getActivity().model.setOpenedFromCatroid(true);
launchActivityRule.getActivity().model.setOpenedFromFormulaEditorInCatroid(true);

onColorPickerView()
.performOpenColorPicker();
Expand All @@ -161,10 +162,52 @@ public void dontShowAlphaSliderFromCatrobat() {

onView(withId(R.id.color_alpha_slider))
.check(matches(not(isDisplayed())));

onColorPickerView()
.onPositiveButton()
.perform(click());

int currentSelectColor = toolReference.getTool().getDrawPaint().getColor();

onColorPickerView()
.performOpenColorPicker();

onView(allOf(withId(R.id.color_picker_tab_icon), withBackground(R.drawable.ic_color_picker_tab_rgba))).perform(click());

onView(withId(R.id.color_picker_base_layout))
.perform(swipeUp());

onView(withId(R.id.color_picker_alpha_row))
.check(matches(not(isDisplayed())));

onView(withId(R.id.color_picker_color_rgb_hex))
.check(matches(withText(String.format("#%02X%02X%02X", Color.red(currentSelectColor), Color.green(currentSelectColor), Color.blue(currentSelectColor)))));
}

@Test
public void showAlphaSliderIfNotCatrobatFlagSet() {
public void showAlphaSliderFromCatroid() {
launchActivityRule.getActivity().model.setOpenedFromCatroid(true);

onColorPickerView()
.performOpenColorPicker();

onView(withId(R.id.color_picker_base_layout))
.perform(swipeUp());

onView(withId(R.id.color_alpha_slider))
.check(matches(isDisplayed()));

onView(allOf(withId(R.id.color_picker_tab_icon), withBackground(R.drawable.ic_color_picker_tab_hsv))).perform(click());

onView(withId(R.id.color_picker_base_layout))
.perform(swipeUp());

onView(withId(R.id.color_alpha_slider))
.check(matches(isDisplayed()));
}

@Test
public void showAlphaSliderIfNotCatroidFlagSet() {
onColorPickerView()
.performOpenColorPicker();

Expand Down Expand Up @@ -682,6 +725,9 @@ public void alphaValueIsSetInSliderWhenChangedInSeekBar() {
// set color to value #7F000000, alpha seekbar 49%
onView(withId(R.id.color_picker_color_rgb_seekbar_alpha)).perform(touchCenterMiddle());
onView(allOf(withId(R.id.color_picker_tab_icon), withBackground(R.drawable.ic_color_picker_tab_preset))).perform(scrollTo(), click());
onColorPickerView()
.onPositiveButton()
.perform(click());
onToolProperties()
.checkMatchesColor(Color.parseColor("#7F000000"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Paintroid: An image manipulation application for Android.
* Copyright (C) 2010-2021 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.espresso.tools

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import org.catrobat.paintroid.MainActivity
import org.catrobat.paintroid.R
import org.catrobat.paintroid.test.espresso.util.UiMatcher.withProgress
import org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction
import org.catrobat.paintroid.test.utils.ScreenshotOnFailRule
import org.catrobat.paintroid.tools.ToolReference
import org.catrobat.paintroid.tools.ToolType
import org.catrobat.paintroid.tools.implementation.DEFAULT_DRAG_IN_PERCENT
import org.catrobat.paintroid.tools.implementation.DEFAULT_PRESSURE_IN_PERCENT
import org.catrobat.paintroid.tools.implementation.SmudgeTool
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class SmudgeToolIntegrationTest {

@get:Rule
var launchActivityRule = ActivityTestRule(MainActivity::class.java)

@get:Rule
var screenshotOnFailRule = ScreenshotOnFailRule()

private lateinit var toolReference: ToolReference

@Before
fun setUp() {
toolReference = launchActivityRule.activity.toolReference
ToolBarViewInteraction.onToolBarView().performSelectTool(ToolType.SMUDGE)
}

@Test
fun testSmudgeToolOptionsDialog() {
val smudgeTool = toolReference.tool as SmudgeTool
ToolBarViewInteraction.onToolBarView()
.performClickSelectedToolButton()

val pressureInput = onView(withId(R.id.pocketpaint_smudge_tool_dialog_pressure_input))
val pressureSeekBar = onView(withId(R.id.pocketpaint_pressure_seek_bar))
val testPressureText = "100"
pressureInput.check(matches(withText(Integer.toString(DEFAULT_PRESSURE_IN_PERCENT))))
pressureInput.perform(replaceText(testPressureText), ViewActions.closeSoftKeyboard())
pressureInput.check(matches(withText(testPressureText)))
pressureSeekBar.check(matches(withProgress(testPressureText.toInt())))
val expectedPressure = 1f
Assert.assertEquals(expectedPressure, smudgeTool.maxPressure)

val dragInput = onView(withId(R.id.pocketpaint_smudge_tool_dialog_drag_input))
val dragSeekBar = onView(withId(R.id.pocketpaint_drag_seek_bar))
val testDragText = "100"
dragInput.check(matches(withText(Integer.toString(DEFAULT_DRAG_IN_PERCENT))))
dragInput.perform(replaceText(testDragText), ViewActions.closeSoftKeyboard())
dragInput.check(matches(withText(testDragText)))
dragSeekBar.check(matches(withProgress(testDragText.toInt())))
val expectedMaxSize = 25f
val expectedMinSize = 25f
Assert.assertEquals(expectedMaxSize, smudgeTool.maxSmudgeSize)
Assert.assertEquals(expectedMinSize, smudgeTool.minSmudgeSize)

// Close tool options
ToolBarViewInteraction.onToolBarView()
.performClickSelectedToolButton()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,44 @@ class TransformToolIntegrationTest {
assertEquals(scale, perspective.scale, 0.0001f)
}

@Test
fun testTransformToolSetCenterCloseCenter() {
drawPlus(layerModel.currentLayer!!.bitmap!!, initialWidth / 2)
onToolBarView()
.performSelectTool(ToolType.TRANSFORM)

runBlocking {
onTransformToolOptionsView().performSetCenterClick()
}
onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.BOTTOM_RIGHT_CLOSE_CENTER))
runBlocking {
TopBarViewInteraction.onTopBarView().performClickCheckmark()
delay(1500)
}
assertThat(toolSelectionBoxWidth, lessThan(initialWidth.toFloat()))
assertThat(toolSelectionBoxHeight, lessThan(initialHeight.toFloat()))
}

@Test
fun testTransformToolSetCenterFarCenter() {
drawPlus(layerModel.currentLayer!!.bitmap!!, initialWidth / 2)
onToolBarView()
.performSelectTool(ToolType.TRANSFORM)

runBlocking {
onTransformToolOptionsView().performSetCenterClick()
}
onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.BOTTOM_RIGHT_CORNER))
runBlocking {
TopBarViewInteraction.onTopBarView().performClickCheckmark()
delay(1500)
}
assertThat(toolSelectionBoxWidth, greaterThan(initialWidth.toFloat()))
assertThat(toolSelectionBoxHeight, greaterThan(initialHeight.toFloat()))
}

companion object {
private fun drawPlus(bitmap: Bitmap, lineLength: Int) {
val horizontalStartX = bitmap.width / 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ public float[] calculateCoordinates(View view) {
return calculatePercentageOffset(view, .75f, .75f);
}
},
BOTTOM_RIGHT_CLOSE_CENTER {
@Override
public float[] calculateCoordinates(View view) {
return calculatePercentageOffset(view, .55f, .55f);
}
},
BOTTOM_RIGHT_CORNER {
@Override
public float[] calculateCoordinates(View view) {
return calculatePercentageOffset(view, 1f, 1f);
}
},
BOTTOM_MIDDLE {
@Override
public float[] calculateCoordinates(View view) {
Expand Down
Loading

0 comments on commit 4230a3e

Please sign in to comment.