Skip to content

Commit

Permalink
PAINTROID-388 import images via overflow menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Tscheppe committed Jun 22, 2022
1 parent 4a3c79b commit e340dd0
Show file tree
Hide file tree
Showing 25 changed files with 113 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class MenuFileActivityIntegrationTest {
onDrawingSurfaceView().perform(touchAt(MIDDLE))
onTopBarView().performOpenMoreOptions()
onView(withText(R.string.menu_load_image)).perform(click())
onView(withText(R.string.menu_load_image)).check(matches(isDisplayed()))
onView(withText(R.string.menu_replace_image)).perform(click())
onView(withText(R.string.dialog_warning_new_image)).check(matches(isDisplayed()))
onView(withText(R.string.save_button_text)).check(matches(isDisplayed()))
onView(withText(R.string.discard_button_text)).check(matches(isDisplayed()))
Expand All @@ -152,6 +152,7 @@ class MenuFileActivityIntegrationTest {
Intents.intending(hasAction(Intent.ACTION_GET_CONTENT)).respondWith(resultCancel)
onTopBarView().performOpenMoreOptions()
onView(withText(R.string.menu_load_image)).perform(click())
onView(withText(R.string.menu_replace_image)).perform(click())
onView(withText(R.string.discard_button_text)).perform(click())
onView(withText(R.string.dialog_warning_new_image)).check(doesNotExist())
onDrawingSurfaceView().checkPixelColor(Color.BLACK, BitmapLocationProvider.MIDDLE)
Expand All @@ -167,6 +168,7 @@ class MenuFileActivityIntegrationTest {
Intents.intending(hasAction(Intent.ACTION_GET_CONTENT)).respondWith(resultOK)
onTopBarView().performOpenMoreOptions()
onView(withText(R.string.menu_load_image)).perform(click())
onView(withText(R.string.menu_replace_image)).perform(click())
onView(withText(R.string.discard_button_text)).perform(click())
onView(withText(R.string.dialog_warning_new_image)).check(doesNotExist())
onDrawingSurfaceView().checkPixelColor(Color.BLACK, BitmapLocationProvider.MIDDLE)
Expand Down Expand Up @@ -404,6 +406,7 @@ class MenuFileActivityIntegrationTest {
createImageIntent()
onTopBarView().performOpenMoreOptions()
onView(withText(R.string.menu_load_image)).perform(click())
onView(withText(R.string.menu_replace_image)).perform(click())
onView(withText(R.string.dialog_warning_new_image)).check(doesNotExist())
onDrawingSurfaceView().perform(touchAt(MIDDLE))
onTopBarView().performOpenMoreOptions()
Expand Down Expand Up @@ -510,6 +513,7 @@ class MenuFileActivityIntegrationTest {
Intents.intending(hasAction(Intent.ACTION_GET_CONTENT)).respondWith(result)
onTopBarView().performOpenMoreOptions()
onView(withText(R.string.menu_load_image)).perform(click())
onView(withText(R.string.menu_replace_image)).perform(click())
ToolBarViewInteraction.onToolBarView().performSelectTool(ToolType.ERASER)
onDrawingSurfaceView().checkPixelColor(Color.BLACK, BitmapLocationProvider.MIDDLE)
onDrawingSurfaceView().perform(touchAt(MIDDLE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class OraFileFormatIntegrationTest {
Intents.intending(IntentMatchers.hasAction(Intent.ACTION_GET_CONTENT)).respondWith(resultOK)
onTopBarView().performOpenMoreOptions()
onView(withText(R.string.menu_load_image)).perform(ViewActions.click())
onView(withText(R.string.menu_replace_image)).perform(ViewActions.click())
LayerMenuViewInteraction.onLayerMenuView()
.performOpen()
.checkLayerCount(3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void testSaveImage() throws IOException {
onTopBarView()
.performOpenMoreOptions();
onView(withText(R.string.menu_load_image)).perform(click());

onView(withText(R.string.menu_replace_image)).perform(click());
onTopBarView()
.performOpenMoreOptions();
onView(withText(R.string.menu_save_image)).perform(click());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void testLoadWithoutChange() {
.performOpenMoreOptions();

onView(withText(R.string.menu_load_image)).perform(click());
onView(withText(R.string.menu_replace_image)).perform(click());
onView(withText(R.string.dialog_warning_new_image)).check(doesNotExist());

onDrawingSurfaceView()
Expand All @@ -149,6 +150,7 @@ public void testLoadWithChange() {
.performOpenMoreOptions();

onView(withText(R.string.menu_load_image)).perform(click());
onView(withText(R.string.menu_replace_image)).perform(click());
onView(withText(R.string.dialog_warning_new_image)).check(doesNotExist());

onDrawingSurfaceView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class OpenedFromPocketCodeWithImageTest {
.performOpenMoreOptions()
onView(ViewMatchers.withText(R.string.menu_load_image))
.perform(click())
onView(ViewMatchers.withText(R.string.menu_replace_image)).perform(click())
onView(ViewMatchers.withText(R.string.dialog_warning_new_image))
.check(ViewAssertions.doesNotExist())
DrawingSurfaceInteraction.onDrawingSurfaceView()
Expand All @@ -143,6 +144,7 @@ class OpenedFromPocketCodeWithImageTest {
.performOpenMoreOptions()
onView(ViewMatchers.withText(R.string.menu_load_image))
.perform(click())
onView(ViewMatchers.withText(R.string.menu_replace_image)).perform(click())
onView(ViewMatchers.withText(R.string.dialog_warning_new_image))
.check(ViewAssertions.doesNotExist())
DrawingSurfaceInteraction.onDrawingSurfaceView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import android.graphics.PointF;

import org.catrobat.paintroid.command.Command;
import org.catrobat.paintroid.command.implementation.AddLayerCommand;
import org.catrobat.paintroid.command.implementation.AddEmptyLayerCommand;
import org.catrobat.paintroid.command.implementation.ColorChangedCommand;
import org.catrobat.paintroid.command.implementation.CompositeCommand;
import org.catrobat.paintroid.command.implementation.CropCommand;
Expand Down Expand Up @@ -84,8 +84,8 @@ public void testCreateResetCommand() {

@Test
public void testCreateAddLayerCommand() {
Command command = commandFactory.createAddLayerCommand();
assertThat(command, is(instanceOf(AddLayerCommand.class)));
Command command = commandFactory.createAddEmptyLayerCommand();
assertThat(command, is(instanceOf(AddEmptyLayerCommand.class)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import android.graphics.Color;

import org.catrobat.paintroid.command.Command;
import org.catrobat.paintroid.command.implementation.AddLayerCommand;
import org.catrobat.paintroid.command.implementation.AddEmptyLayerCommand;
import org.catrobat.paintroid.command.implementation.ResizeCommand;
import org.catrobat.paintroid.common.CommonFactory;
import org.catrobat.paintroid.model.Layer;
Expand Down Expand Up @@ -83,12 +83,12 @@ public void testBitmapKeepsDrawings() {
public void testLayerStayInSameOrderOnResize() {
layerModel.getLayerAt(0).getBitmap().eraseColor(Color.GREEN);

Command addLayerCommand = new AddLayerCommand(new CommonFactory());
Command addLayerCommand = new AddEmptyLayerCommand(new CommonFactory());
addLayerCommand.run(canvasUnderTest, layerModel);

layerModel.getLayerAt(0).getBitmap().eraseColor(Color.YELLOW);

addLayerCommand = new AddLayerCommand(new CommonFactory());
addLayerCommand = new AddEmptyLayerCommand(new CommonFactory());
addLayerCommand.run(canvasUnderTest, layerModel);

layerModel.getLayerAt(0).getBitmap().eraseColor(Color.BLUE);
Expand All @@ -103,10 +103,10 @@ public void testLayerStayInSameOrderOnResize() {

@Test
public void testAllLayersAreResized() {
Command addLayerCommand = new AddLayerCommand(new CommonFactory());
Command addLayerCommand = new AddEmptyLayerCommand(new CommonFactory());
addLayerCommand.run(canvasUnderTest, layerModel);

addLayerCommand = new AddLayerCommand(new CommonFactory());
addLayerCommand = new AddEmptyLayerCommand(new CommonFactory());
addLayerCommand.run(canvasUnderTest, layerModel);

Command commandUnderTest = new ResizeCommand(NEW_WIDTH, NEW_HEIGHT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void setUp() {
@Test
public void testCreateManyLayers() {
for (int i = 0; i < 10; i++) {
commandManager.addCommand(commandFactory.createAddLayerCommand());
commandManager.addCommand(commandFactory.createAddEmptyLayerCommand());
commandManager.addCommand(commandFactory.createRemoveLayerCommand(1));
}
}
Expand All @@ -83,7 +83,7 @@ public void testMoveLayer() {
final CommandListener listener = mock(CommandListener.class);

commandManager.addCommandListener(listener);
commandManager.addCommand(commandFactory.createAddLayerCommand());
commandManager.addCommand(commandFactory.createAddEmptyLayerCommand());

verify(listener, timeout(1000)).commandPostExecute();
assertThat(layerModel.getLayerCount(), is(2));
Expand All @@ -110,7 +110,7 @@ public void testMergeLayers() {
firstLayer.getBitmap().setPixel(1, 2, Color.BLACK);

commandManager.addCommandListener(listener);
commandManager.addCommand(commandFactory.createAddLayerCommand());
commandManager.addCommand(commandFactory.createAddEmptyLayerCommand());

verify(listener, timeout(1000)).commandPostExecute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import android.graphics.RectF
import com.esotericsoftware.kryo.io.Input
import com.esotericsoftware.kryo.io.Output
import org.catrobat.paintroid.command.Command
import org.catrobat.paintroid.command.implementation.AddLayerCommand
import org.catrobat.paintroid.command.implementation.AddEmptyLayerCommand
import org.catrobat.paintroid.command.implementation.AsyncCommandManager
import org.catrobat.paintroid.command.implementation.CompositeCommand
import org.catrobat.paintroid.command.implementation.CropCommand
Expand Down Expand Up @@ -103,7 +103,7 @@ class CommandSerializationTest {

@Test
fun testSerializeAddLayerCommand() {
expectedModel.commands.add(commandFactory.createAddLayerCommand())
expectedModel.commands.add(commandFactory.createAddEmptyLayerCommand())
assertSerializeAndDeserialize()
}

Expand Down Expand Up @@ -351,7 +351,7 @@ class CommandSerializationTest {
add(commandFactory.createSprayCommand(floatArrayOf(20f, 347.5f, 99.239f), paint))
add(commandFactory.createResizeCommand(400, 200))
add(commandFactory.createRotateCommand(RotateCommand.RotateDirection.ROTATE_RIGHT))
add(commandFactory.createAddLayerCommand())
add(commandFactory.createAddEmptyLayerCommand())
add(commandFactory.createPointCommand(paint, PointF(30.43f, 40.28f)))
}
}
Expand Down Expand Up @@ -382,7 +382,7 @@ class CommandSerializationTest {
return false
}
return when (expectedCommand) {
is AddLayerCommand -> true
is AddEmptyLayerCommand -> true
is CompositeCommand -> equalsCompositeCommand(
expectedCommand, actualCommand as CompositeCommand
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,18 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener {
R.id.pocketpaint_options_export -> presenterMain.saveCopyClicked(true)
R.id.pocketpaint_options_save_image -> presenterMain.saveImageClicked()
R.id.pocketpaint_options_save_duplicate -> presenterMain.saveCopyClicked(false)
R.id.pocketpaint_options_open_image -> presenterMain.loadImageClicked()
R.id.pocketpaint_replace_image -> presenterMain.replaceImageClicked()
R.id.pocketpaint_add_to_current_layer -> presenterMain.addImageToCurrentLayerClicked()
R.id.pocketpaint_options_new_image -> presenterMain.newImageClicked()
R.id.pocketpaint_options_discard_image -> presenterMain.discardImageClicked()
R.id.pocketpaint_options_fullscreen_mode -> presenterMain.enterFullscreenClicked()
R.id.pocketpaint_options_rate_us -> presenterMain.rateUsClicked()
R.id.pocketpaint_options_help -> presenterMain.showHelpClicked()
R.id.pocketpaint_options_about -> presenterMain.showAboutClicked()
android.R.id.home -> presenterMain.backToPocketCodeClicked()
R.id.pocketpaint_share_image_button -> presenterMain.shareImageClicked()
R.id.pocketpaint_options_feedback -> presenterMain.sendFeedback()
R.id.pocketpaint_advanced_settings -> presenterMain.showAdvancedSettingsClicked()
android.R.id.home -> presenterMain.backToPocketCodeClicked()
else -> return false
}
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface CommandFactory {

fun createResetCommand(): Command

fun createAddLayerCommand(): Command
fun createAddEmptyLayerCommand(): Command

fun createSelectLayerCommand(position: Int): Command

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.catrobat.paintroid.common.CommonFactory
import org.catrobat.paintroid.contract.LayerContracts
import org.catrobat.paintroid.model.Layer

class AddLayerCommand(private val commonFactory: CommonFactory) : Command {
class AddEmptyLayerCommand(private val commonFactory: CommonFactory) : Command {

override fun run(canvas: Canvas, layerModel: LayerContracts.Model) {
val layer = Layer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DefaultCommandFactory : CommandFactory {
private val commonFactory = CommonFactory()
override fun createInitCommand(width: Int, height: Int): Command = CompositeCommand().apply {
addCommand(SetDimensionCommand(width, height))
addCommand(AddLayerCommand(commonFactory))
addCommand(AddEmptyLayerCommand(commonFactory))
}

override fun createInitCommand(bitmap: Bitmap): Command = CompositeCommand().apply {
Expand All @@ -57,10 +57,10 @@ class DefaultCommandFactory : CommandFactory {

override fun createResetCommand(): Command = CompositeCommand().apply {
addCommand(ResetCommand())
addCommand(AddLayerCommand(commonFactory))
addCommand(AddEmptyLayerCommand(commonFactory))
}

override fun createAddLayerCommand(): Command = AddLayerCommand(commonFactory)
override fun createAddEmptyLayerCommand(): Command = AddEmptyLayerCommand(commonFactory)

override fun createSelectLayerCommand(position: Int): Command = SelectLayerCommand(position)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ class DefaultCommandManager(
var success = true
var layerCount = layerModel.layerCount
val currentCommandName = command.javaClass.simpleName
val addLayerCommandRegex = AddLayerCommand::class.java.simpleName.toRegex()
val addEmptyLayerCommandRegex = AddEmptyLayerCommand::class.java.simpleName.toRegex()
val mergeLayerCommandRegex = MergeLayersCommand::class.java.simpleName.toRegex()

var backupLayer: LayerContracts.Layer? = null
if (currentCommandName.matches(addLayerCommandRegex)) {
if (currentCommandName.matches(addEmptyLayerCommandRegex)) {
layerCount--
backupLayer = layerModel.getLayerAt(0)
success = layerModel.removeLayerAt(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ package org.catrobat.paintroid.command.serialization
import com.esotericsoftware.kryo.Kryo
import com.esotericsoftware.kryo.io.Input
import com.esotericsoftware.kryo.io.Output
import org.catrobat.paintroid.command.implementation.AddLayerCommand
import org.catrobat.paintroid.command.implementation.AddEmptyLayerCommand
import org.catrobat.paintroid.common.CommonFactory

class AddLayerCommandSerializer(version: Int) : VersionSerializer<AddLayerCommand>(version) {
override fun write(kryo: Kryo, output: Output, command: AddLayerCommand) {
class AddLayerCommandSerializer(version: Int) : VersionSerializer<AddEmptyLayerCommand>(version) {
override fun write(kryo: Kryo, output: Output, command: AddEmptyLayerCommand) {
// Has no member variables to save
}

override fun read(kryo: Kryo, input: Input, type: Class<out AddLayerCommand>): AddLayerCommand =
override fun read(kryo: Kryo, input: Input, type: Class<out AddEmptyLayerCommand>): AddEmptyLayerCommand =
super.handleVersions(this, kryo, input, type)

override fun readCurrentVersion(kryo: Kryo, input: Input, type: Class<out AddLayerCommand>): AddLayerCommand =
AddLayerCommand(CommonFactory())
override fun readCurrentVersion(kryo: Kryo, input: Input, type: Class<out AddEmptyLayerCommand>): AddEmptyLayerCommand =
AddEmptyLayerCommand(CommonFactory())
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.esotericsoftware.kryo.io.Input
import com.esotericsoftware.kryo.io.Output
import org.catrobat.paintroid.command.Command
import org.catrobat.paintroid.command.CommandManager
import org.catrobat.paintroid.command.implementation.AddLayerCommand
import org.catrobat.paintroid.command.implementation.AddEmptyLayerCommand
import org.catrobat.paintroid.command.implementation.CompositeCommand
import org.catrobat.paintroid.command.implementation.CropCommand
import org.catrobat.paintroid.command.implementation.CutCommand
Expand Down Expand Up @@ -103,7 +103,7 @@ class CommandSerializationUtilities(private val activityContext: Context, privat
put(SetDimensionCommand::class.java, SetDimensionCommandSerializer(version))
put(SprayCommand::class.java, SprayCommandSerializer(version))
put(Paint::class.java, PaintSerializer(version, activityContext))
put(AddLayerCommand::class.java, AddLayerCommandSerializer(version))
put(AddEmptyLayerCommand::class.java, AddLayerCommandSerializer(version))
put(SelectLayerCommand::class.java, SelectLayerCommandSerializer(version))
put(LoadCommand::class.java, LoadCommandSerializer(version))
put(TextToolCommand::class.java, TextToolCommandSerializer(version, activityContext))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,54 @@ const val SAVE_IMAGE_DEFAULT = 1
const val SAVE_IMAGE_NEW_EMPTY = 2
const val SAVE_IMAGE_LOAD_NEW = 3
const val SAVE_IMAGE_FINISH = 4

const val LOAD_IMAGE_DEFAULT = 1
const val LOAD_IMAGE_IMPORT_PNG = 2
const val LOAD_IMAGE_CATROID = 3

const val CREATE_FILE_DEFAULT = 1

const val REQUEST_CODE_IMPORT_PNG = 1
const val REQUEST_CODE_LOAD_PICTURE = 2
const val REQUEST_CODE_INTRO = 3

const val PERMISSION_EXTERNAL_STORAGE_SAVE = 1
const val PERMISSION_EXTERNAL_STORAGE_SAVE_COPY = 2
const val PERMISSION_EXTERNAL_STORAGE_SAVE_CONFIRMED_LOAD_NEW = 3
const val PERMISSION_EXTERNAL_STORAGE_SAVE_CONFIRMED_NEW_EMPTY = 4
const val PERMISSION_EXTERNAL_STORAGE_SAVE_CONFIRMED_FINISH = 5
const val PERMISSION_REQUEST_CODE_LOAD_PICTURE = 6
const val PERMISSION_REQUEST_CODE_REPLACE_PICTURE = 6
const val PERMISSION_REQUEST_CODE_IMPORT_PICTURE = 7

const val RESULT_INTRO_MW_NOT_SUPPORTED = 10

class MainActivityConstants private constructor() {
@IntDef(SAVE_IMAGE_DEFAULT, SAVE_IMAGE_NEW_EMPTY, SAVE_IMAGE_LOAD_NEW, SAVE_IMAGE_FINISH)
@IntDef(
SAVE_IMAGE_DEFAULT,
SAVE_IMAGE_NEW_EMPTY,
SAVE_IMAGE_LOAD_NEW,
SAVE_IMAGE_FINISH
)
@Retention(AnnotationRetention.SOURCE)
annotation class SaveImageRequestCode

@IntDef(LOAD_IMAGE_DEFAULT, LOAD_IMAGE_IMPORT_PNG, LOAD_IMAGE_CATROID)
@IntDef(
LOAD_IMAGE_DEFAULT,
LOAD_IMAGE_IMPORT_PNG,
LOAD_IMAGE_CATROID
)
@Retention(AnnotationRetention.SOURCE)
annotation class LoadImageRequestCode

@IntDef(CREATE_FILE_DEFAULT)
@Retention(AnnotationRetention.SOURCE)
annotation class CreateFileRequestCode

@IntDef(REQUEST_CODE_IMPORT_PNG, REQUEST_CODE_LOAD_PICTURE, REQUEST_CODE_INTRO)
@IntDef(
REQUEST_CODE_IMPORT_PNG,
REQUEST_CODE_LOAD_PICTURE,
REQUEST_CODE_INTRO
)
@Retention(AnnotationRetention.SOURCE)
annotation class ActivityRequestCode

Expand All @@ -64,7 +82,7 @@ class MainActivityConstants private constructor() {
PERMISSION_EXTERNAL_STORAGE_SAVE_CONFIRMED_LOAD_NEW,
PERMISSION_EXTERNAL_STORAGE_SAVE_CONFIRMED_NEW_EMPTY,
PERMISSION_EXTERNAL_STORAGE_SAVE_CONFIRMED_FINISH,
PERMISSION_REQUEST_CODE_LOAD_PICTURE,
PERMISSION_REQUEST_CODE_REPLACE_PICTURE,
PERMISSION_REQUEST_CODE_IMPORT_PICTURE
)
@Retention(AnnotationRetention.SOURCE)
Expand Down

0 comments on commit e340dd0

Please sign in to comment.