Skip to content

Commit

Permalink
PE-72 Transform original brush drawing into a Shape
Browse files Browse the repository at this point in the history
- BrushDrawingView is now called DrawingView
- draw parameters (color, opacity, thickness) goes through a ShapeBuilder
- undo-redo performs the same for all Shapes
- fixed tests
  • Loading branch information
stephanepechard authored and burhanrashid52 committed Jul 10, 2021
1 parent eb7b0c1 commit 5c470cf
Show file tree
Hide file tree
Showing 37 changed files with 824 additions and 1,061 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ We can customize our brush and paint with different set of property. To start dr
| Type | Method |
| ------------- | ------------- |
| Enable/Disable | `mPhotoEditor.setBrushDrawingMode(true);` |
| Brush Size (px) | `mPhotoEditor.setBrushSize(brushSize)` |
| Color Opacity (In %) | `mPhotoEditor.setOpacity(opacity)` |
| Brush Color | `mPhotoEditor.setBrushColor(colorCode)` |
| Brush Eraser | `mPhotoEditor.brushEraser()` |
| Shape (free hand, oval, rectangle) | `mPhotoEditor.addShape(shape)` |
| Shape (brush, line, oval, rectangle) | `mPhotoEditor.addShape(shape)` |
| Shape size (px) | `mPhotoEditor.setBrushSize(brushSize)` |
| Shape opacity (In %) | `mPhotoEditor.setOpacity(opacity)` |
| Shape color | `mPhotoEditor.setBrushColor(colorCode)` |

**Note**: Whenever we set any property of a brush for drawing it will automatically enable the drawing mode

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void checkIfActivityIsLaunched() {
public void checkIfBrushIsEnabledWhenClickedOnBrushTool() {
EditImageActivity editImageActivity = mActivityRule.launchActivity(null);
assertFalse(editImageActivity.mPhotoEditor.getBrushDrawableMode());
onView(withText(R.string.label_brush)).perform(click());
onView(withText(R.string.label_shape)).perform(click());
assertTrue(editImageActivity.mPhotoEditor.getBrushDrawableMode());
}

Expand All @@ -69,13 +69,6 @@ public void checkIfShapeIsEnabledWhenClickedOnBrushTool() {
onView(withText(R.string.label_shape)).check(matches(isDisplayed()));
}

@Test
public void checkIfEraserIsEnabledWhenClickedOnEraserTool() {
mActivityRule.launchActivity(null);
onView(withText(R.string.label_eraser)).perform(click());
onView(withText(R.string.label_eraser_mode)).check(matches(isDisplayed()));
}

@Test
public void checkIfEmojiIsDisplayedWhenEmojiIsSelected() {
Context context = mActivityRule.launchActivity(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
import ja.burhanrashid52.photoeditor.PhotoEditorView;
import ja.burhanrashid52.photoeditor.PhotoFilter;
import ja.burhanrashid52.photoeditor.SaveSettings;
import ja.burhanrashid52.photoeditor.ShapeBuilder;
import ja.burhanrashid52.photoeditor.ShapeType;
import ja.burhanrashid52.photoeditor.shape.ShapeBuilder;
import ja.burhanrashid52.photoeditor.shape.ShapeType;
import ja.burhanrashid52.photoeditor.TextStyleBuilder;
import ja.burhanrashid52.photoeditor.ViewType;

Expand Down Expand Up @@ -357,21 +357,18 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@Override
public void onColorChanged(int colorCode) {
mPhotoEditor.updateShape(mShapeBuilder.withShapeColor(colorCode));
mPhotoEditor.setBrushColor(colorCode);
mTxtCurrentTool.setText(R.string.label_brush);
}

@Override
public void onOpacityChanged(int opacity) {
mPhotoEditor.updateShape(mShapeBuilder.withShapeOpacity(opacity));
mPhotoEditor.setOpacity(opacity);
mTxtCurrentTool.setText(R.string.label_brush);
}

@Override
public void onBrushSizeChanged(int brushSize) {
mPhotoEditor.updateShape(mShapeBuilder.withShapeSize(brushSize));
mPhotoEditor.setBrushSize(brushSize);
public void onShapeSizeChanged(int shapeSize) {
mPhotoEditor.updateShape(mShapeBuilder.withShapeSize(shapeSize));
mTxtCurrentTool.setText(R.string.label_brush);
}

Expand Down Expand Up @@ -417,13 +414,8 @@ public void onFilterSelected(PhotoFilter photoFilter) {
@Override
public void onToolSelected(ToolType toolType) {
switch (toolType) {
case BRUSH:
mPhotoEditor.setBrushDrawingMode(true);
mTxtCurrentTool.setText(R.string.label_brush);
showBottomSheetDialogFragment(mPropertiesBSFragment);
break;
case SHAPE:
mPhotoEditor.setShapeDrawingMode();
mPhotoEditor.setBrushDrawingMode(true);
mShapeBuilder = new ShapeBuilder();
mPhotoEditor.updateShape(mShapeBuilder);
mTxtCurrentTool.setText(R.string.label_shape);
Expand All @@ -439,10 +431,6 @@ public void onToolSelected(ToolType toolType) {
mTxtCurrentTool.setText(R.string.label_text);
});
break;
case ERASER:
mPhotoEditor.brushEraser();
mTxtCurrentTool.setText(R.string.label_eraser_mode);
break;
case FILTER:
mTxtCurrentTool.setText(R.string.label_filter);
showFilter(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface Properties {

void onOpacityChanged(int opacity);

void onBrushSizeChanged(int brushSize);
void onShapeSizeChanged(int shapeSize);
}

@Override
Expand Down Expand Up @@ -77,7 +77,7 @@ public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
break;
case R.id.sbSize:
if (mProperties != null) {
mProperties.onBrushSizeChanged(i);
mProperties.onShapeSizeChanged(i);
}
break;
}
Expand All @@ -92,4 +92,4 @@ public void onStartTrackingTouch(SeekBar seekBar) {
public void onStopTrackingTouch(SeekBar seekBar) {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

import ja.burhanrashid52.photoeditor.ShapeType;
import ja.burhanrashid52.photoeditor.shape.ShapeType;

public class ShapeBSFragment extends BottomSheetDialogFragment implements SeekBar.OnSeekBarChangeListener {

Expand All @@ -29,7 +29,7 @@ public interface Properties {

void onOpacityChanged(int opacity);

void onBrushSizeChanged(int brushSize);
void onShapeSizeChanged(int shapeSize);

void onShapePicked(ShapeType shapeType);
}
Expand All @@ -54,12 +54,14 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

// shape picker
shapeGroup.setOnCheckedChangeListener((group, checkedId) -> {
if (checkedId == R.id.ovalRadioButton) {
if (checkedId == R.id.lineRadioButton) {
mProperties.onShapePicked(ShapeType.LINE);
} else if (checkedId == R.id.ovalRadioButton) {
mProperties.onShapePicked(ShapeType.OVAL);
} else if (checkedId == R.id.rectRadioButton) {
mProperties.onShapePicked(ShapeType.RECTANGLE);
} else {
mProperties.onShapePicked(ShapeType.LINE);
mProperties.onShapePicked(ShapeType.BRUSH);
}
});

Expand Down Expand Up @@ -93,7 +95,7 @@ public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
break;
case R.id.shapeSize:
if (mProperties != null) {
mProperties.onBrushSizeChanged(i);
mProperties.onShapeSizeChanged(i);
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ public class EditingToolsAdapter extends RecyclerView.Adapter<EditingToolsAdapte

public EditingToolsAdapter(OnItemSelected onItemSelected) {
mOnItemSelected = onItemSelected;
mToolList.add(new ToolModel("Brush", R.drawable.ic_brush, ToolType.BRUSH));
mToolList.add(new ToolModel("Shape", R.drawable.ic_oval, ToolType.SHAPE));
mToolList.add(new ToolModel("Text", R.drawable.ic_text, ToolType.TEXT));
mToolList.add(new ToolModel("Eraser", R.drawable.ic_eraser, ToolType.ERASER));
mToolList.add(new ToolModel("Filter", R.drawable.ic_photo_filter, ToolType.FILTER));
mToolList.add(new ToolModel("Emoji", R.drawable.ic_insert_emoticon, ToolType.EMOJI));
mToolList.add(new ToolModel("Sticker", R.drawable.ic_sticker, ToolType.STICKER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
* @since 5/23/2018
*/
public enum ToolType {
BRUSH,
SHAPE,
TEXT,
ERASER,
FILTER,
EMOJI,
STICKER
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/layout/fragment_bottom_shapes_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
app:layout_constraintTop_toBottomOf="@id/shapeType">

<RadioButton
android:id="@+id/lineRadioButton"
android:id="@+id/brushRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/label_brush" />

<RadioButton
android:id="@+id/lineRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_line" />

<RadioButton
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<string name="label_line">Line</string>
<string name="label_emoji">Emoji</string>
<string name="label_sticker">Sticker</string>
<string name="label_eraser">Eraser</string>
<string name="label_eraser_mode">Eraser Mode</string>
<string name="label_text">Text</string>
<string name="label_filter">Filter</string>
<string name="label_adjust">Adjust</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ void clearHelperBox() {
mViewState.clearCurrentSelectedView();
}

public void clearAllViews(BrushDrawingView brushDrawingView) {
public void clearAllViews(DrawingView drawingView) {
for (int i = 0; i < mViewState.getAddedViewsCount(); i++) {
mViewGroup.removeView(mViewState.getAddedView(i));
}
if (mViewState.containsAddedView(brushDrawingView)) {
mViewGroup.addView(brushDrawingView);
if (mViewState.containsAddedView(drawingView)) {
mViewGroup.addView(drawingView);
}
mViewState.clearAddedViews();
mViewState.clearRedoViews();

if (brushDrawingView != null)
brushDrawingView.clearAll();
if (drawingView != null)
drawingView.clearAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public void setOnPhotoEditorListener(@Nullable OnPhotoEditorListener onPhotoEdit
}

@Override
public void onViewAdd(BrushDrawingView brushDrawingView) {
public void onViewAdd(DrawingView drawingView) {
if (mViewState.getRedoViewsCount() > 0) {
mViewState.popRedoView();
}
mViewState.addAddedView(brushDrawingView);
mViewState.addAddedView(drawingView);
if (mOnPhotoEditorListener != null) {
mOnPhotoEditorListener.onAddViewListener(
ViewType.BRUSH_DRAWING,
Expand All @@ -40,12 +40,12 @@ public void onViewAdd(BrushDrawingView brushDrawingView) {
}

@Override
public void onViewRemoved(BrushDrawingView brushDrawingView) {
public void onViewRemoved(DrawingView drawingView) {
if (mViewState.getAddedViewsCount() > 0) {
View removeView = mViewState.removeAddedView(
mViewState.getAddedViewsCount() - 1
);
if (!(removeView instanceof BrushDrawingView)) {
if (!(removeView instanceof DrawingView)) {
mPhotoEditorView.removeView(removeView);
}
mViewState.pushRedoView(removeView);
Expand Down
Loading

0 comments on commit 5c470cf

Please sign in to comment.