diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/test/BricksHelpUrlTest.java b/catroid/src/androidTest/java/org/catrobat/catroid/test/BricksHelpUrlTest.java index 734278d4e9b..d0163ed9691 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/test/BricksHelpUrlTest.java +++ b/catroid/src/androidTest/java/org/catrobat/catroid/test/BricksHelpUrlTest.java @@ -380,6 +380,8 @@ public class BricksHelpUrlTest { "https://wiki.catrobat.org/bin/view/Documentation/Brick%20Documentation/Data%20Bricks/#ShowTextColorSizeAlignmentBrick"); brickToHelpUrlMapping.put("org.catrobat.catroid.content.bricks.RunningStitchBrick", "https://wiki.catrobat.org/bin/view/Documentation/Brick%20Documentation/Embroidery%20Bricks/#RunningStitchBrick"); + brickToHelpUrlMapping.put("org.catrobat.catroid.content.bricks.StopRunningStitchBrick", + "https://wiki.catrobat.org/bin/view/Documentation/Brick%20Documentation/Embroidery%20Bricks/#StopRunningStitchBrick"); } @Parameterized.Parameters(name = "{0}") diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/test/content/bricks/BrickCategoryTest.java b/catroid/src/androidTest/java/org/catrobat/catroid/test/content/bricks/BrickCategoryTest.java index 772a9d33e9d..ec383e5e73c 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/test/content/bricks/BrickCategoryTest.java +++ b/catroid/src/androidTest/java/org/catrobat/catroid/test/content/bricks/BrickCategoryTest.java @@ -164,6 +164,7 @@ import org.catrobat.catroid.content.bricks.StampBrick; import org.catrobat.catroid.content.bricks.StitchBrick; import org.catrobat.catroid.content.bricks.StopAllSoundsBrick; +import org.catrobat.catroid.content.bricks.StopRunningStitchBrick; import org.catrobat.catroid.content.bricks.StopScriptBrick; import org.catrobat.catroid.content.bricks.TapAtBrick; import org.catrobat.catroid.content.bricks.ThinkBubbleBrick; @@ -234,7 +235,8 @@ public static Collection data() { SetBounceBrick.class, SetFrictionBrick.class)}, {"Embroidery", Arrays.asList(StitchBrick.class, - RunningStitchBrick.class)}, + RunningStitchBrick.class, + StopRunningStitchBrick.class)}, {"Event", Arrays.asList(WhenStartedBrick.class, WhenBrick.class, WhenTouchDownBrick.class, diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/test/embroidery/RunningStitchTest.java b/catroid/src/androidTest/java/org/catrobat/catroid/test/embroidery/RunningStitchTest.java index 6ac5c869e84..39ca1400983 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/test/embroidery/RunningStitchTest.java +++ b/catroid/src/androidTest/java/org/catrobat/catroid/test/embroidery/RunningStitchTest.java @@ -130,4 +130,19 @@ public void testInvalidSetStartCoordinates() { Mockito.verify(runningStitchType, Mockito.times(0)).setStartCoordinates(anyFloat(), anyFloat()); } + + @Test + public void testDeactivateRunningStitch() { + runningStitch.activateStitching(sprite, runningStitchType); + runningStitch.deactivate(); + final float xCoord = 1; + final float yCoord = 2; + runningStitch.setStartCoordinates(xCoord, yCoord); + runningStitch.update(); + + Mockito.verify(runningStitchType, Mockito.times(0)).setStartCoordinates(xCoord, yCoord); + Mockito.verify(spriteLook, Mockito.times(0)).getXInUserInterfaceDimensionUnit(); + Mockito.verify(spriteLook, Mockito.times(0)).getYInUserInterfaceDimensionUnit(); + Mockito.verify(runningStitchType, Mockito.times(0)).update(anyFloat(), anyFloat()); + } } diff --git a/catroid/src/main/java/org/catrobat/catroid/content/ActionFactory.java b/catroid/src/main/java/org/catrobat/catroid/content/ActionFactory.java index 24a56ca947f..2bb9d9b343f 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/ActionFactory.java +++ b/catroid/src/main/java/org/catrobat/catroid/content/ActionFactory.java @@ -153,6 +153,7 @@ import org.catrobat.catroid.content.actions.StopAllScriptsAction; import org.catrobat.catroid.content.actions.StopAllSoundsAction; import org.catrobat.catroid.content.actions.StopOtherScriptsAction; +import org.catrobat.catroid.content.actions.StopRunningStitchAction; import org.catrobat.catroid.content.actions.StopThisScriptAction; import org.catrobat.catroid.content.actions.TapAtAction; import org.catrobat.catroid.content.actions.ThinkSayBubbleAction; @@ -865,6 +866,12 @@ public Action createRunningStitchAction(Sprite sprite, Formula length) { return action; } + public static Action createStopRunningStitchAction(Sprite sprite) { + StopRunningStitchAction action = Actions.action(StopRunningStitchAction.class); + action.setSprite(sprite); + return action; + } + public static Action eventSequence(Script script) { return new ScriptSequenceAction(script); } diff --git a/catroid/src/main/java/org/catrobat/catroid/content/actions/StopRunningStitchAction.java b/catroid/src/main/java/org/catrobat/catroid/content/actions/StopRunningStitchAction.java new file mode 100644 index 00000000000..5d16a8bf174 --- /dev/null +++ b/catroid/src/main/java/org/catrobat/catroid/content/actions/StopRunningStitchAction.java @@ -0,0 +1,41 @@ +/* + * Catroid: An on-device visual programming system for Android devices + * Copyright (C) 2010-2018 The Catrobat Team + * () + * + * 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. + * + * An additional term exception under section 7 of the GNU Affero + * General Public License, version 3, is available at + * http://developer.catrobat.org/license_additional_term + * + * 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 . + */ +package org.catrobat.catroid.content.actions; + +import com.badlogic.gdx.scenes.scene2d.actions.TemporalAction; + +import org.catrobat.catroid.content.Sprite; + +public class StopRunningStitchAction extends TemporalAction { + + private Sprite sprite; + + @Override + protected void update(float delta) { + sprite.runningStitch.deactivate(); + } + + public void setSprite(Sprite sprite) { + this.sprite = sprite; + } +} diff --git a/catroid/src/main/java/org/catrobat/catroid/content/bricks/StopRunningStitchBrick.java b/catroid/src/main/java/org/catrobat/catroid/content/bricks/StopRunningStitchBrick.java new file mode 100644 index 00000000000..2d50d72c62a --- /dev/null +++ b/catroid/src/main/java/org/catrobat/catroid/content/bricks/StopRunningStitchBrick.java @@ -0,0 +1,43 @@ +/* + * Catroid: An on-device visual programming system for Android devices + * Copyright (C) 2010-2018 The Catrobat Team + * () +* + * 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. + * + * An additional term exception under section 7 of the GNU Affero + * General Public License, version 3, is available at + * http://developer.catrobat.org/license_additional_term + * + * 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 . + */ +package org.catrobat.catroid.content.bricks; + +import org.catrobat.catroid.R; +import org.catrobat.catroid.content.ActionFactory; +import org.catrobat.catroid.content.Sprite; +import org.catrobat.catroid.content.actions.ScriptSequenceAction; + +public class StopRunningStitchBrick extends BrickBaseType { + + private static final long serialVersionUID = 1L; + + @Override + public int getViewResource() { + return R.layout.brick_stop_running_stitch; + } + + @Override + public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) { + sequence.addAction(ActionFactory.createStopRunningStitchAction(sprite)); + } +} diff --git a/catroid/src/main/java/org/catrobat/catroid/embroidery/RunningStitch.java b/catroid/src/main/java/org/catrobat/catroid/embroidery/RunningStitch.java index 29eb5cdce71..3431d5baacf 100644 --- a/catroid/src/main/java/org/catrobat/catroid/embroidery/RunningStitch.java +++ b/catroid/src/main/java/org/catrobat/catroid/embroidery/RunningStitch.java @@ -61,4 +61,10 @@ public void resume() { isRunning = true; } } + + public void deactivate() { + isRunning = false; + type = null; + sprite = null; + } } diff --git a/catroid/src/main/java/org/catrobat/catroid/io/XstreamSerializer.java b/catroid/src/main/java/org/catrobat/catroid/io/XstreamSerializer.java index 80a0578fcdb..ee4813d15b4 100644 --- a/catroid/src/main/java/org/catrobat/catroid/io/XstreamSerializer.java +++ b/catroid/src/main/java/org/catrobat/catroid/io/XstreamSerializer.java @@ -202,6 +202,7 @@ import org.catrobat.catroid.content.bricks.StampBrick; import org.catrobat.catroid.content.bricks.StitchBrick; import org.catrobat.catroid.content.bricks.StopAllSoundsBrick; +import org.catrobat.catroid.content.bricks.StopRunningStitchBrick; import org.catrobat.catroid.content.bricks.StopScriptBrick; import org.catrobat.catroid.content.bricks.TapAtBrick; import org.catrobat.catroid.content.bricks.ThinkBubbleBrick; @@ -510,6 +511,7 @@ private void prepareXstream(Class projectClass, Class sceneClass) { xstream.alias("brick", SetTextBrick.class); xstream.alias("brick", ShowTextColorSizeAlignmentBrick.class); xstream.alias("brick", StitchBrick.class); + xstream.alias("brick", StopRunningStitchBrick.class); xstream.alias("brick", RunningStitchBrick.class); xstream.alias("brick", WaitTillIdleBrick.class); xstream.alias("brick", WhenRaspiPinChangedBrick.class); diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/CategoryBricksFactory.java b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/CategoryBricksFactory.java index 11f75c69900..a44c69540b9 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/CategoryBricksFactory.java +++ b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/CategoryBricksFactory.java @@ -174,6 +174,7 @@ import org.catrobat.catroid.content.bricks.StampBrick; import org.catrobat.catroid.content.bricks.StitchBrick; import org.catrobat.catroid.content.bricks.StopAllSoundsBrick; +import org.catrobat.catroid.content.bricks.StopRunningStitchBrick; import org.catrobat.catroid.content.bricks.StopScriptBrick; import org.catrobat.catroid.content.bricks.TapAtBrick; import org.catrobat.catroid.content.bricks.ThinkBubbleBrick; @@ -648,6 +649,7 @@ private List setupEmbroideryCategoryList() { List embroideryBrickList = new ArrayList<>(); embroideryBrickList.add(new StitchBrick()); embroideryBrickList.add(new RunningStitchBrick(new Formula(BrickValues.STITCH_LENGTH))); + embroideryBrickList.add(new StopRunningStitchBrick()); return embroideryBrickList; } diff --git a/catroid/src/main/res/layout/brick_stop_running_stitch.xml b/catroid/src/main/res/layout/brick_stop_running_stitch.xml new file mode 100644 index 00000000000..aecfff02b13 --- /dev/null +++ b/catroid/src/main/res/layout/brick_stop_running_stitch.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/catroid/src/main/res/values/strings.xml b/catroid/src/main/res/values/strings.xml index 81601ceeb60..fa4ed03aae8 100644 --- a/catroid/src/main/res/values/strings.xml +++ b/catroid/src/main/res/values/strings.xml @@ -1173,6 +1173,7 @@ Stitch Start running stitch with length + Stop current stitch