diff --git a/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java b/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java index 607712d..9072c21 100644 --- a/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java +++ b/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java @@ -14,6 +14,8 @@ import java.util.LinkedHashMap; import java.util.Map; public class MyCanvas extends View { + private Paint mBackgroundPaint; + private Paint mPaint; private Path mPath; private Map mPaths; @@ -28,6 +30,10 @@ public class MyCanvas extends View { public MyCanvas(Context context, AttributeSet attrs) { super(context, attrs); + mBackgroundPaint = new Paint(); + mBackgroundPaint.setColor(Color.WHITE); + mBackgroundPaint.setStyle(Paint.Style.FILL); + mPath = new Path(); mPaint = new Paint(); mPaint.setColor(Color.BLACK); @@ -60,6 +66,10 @@ public class MyCanvas extends View { invalidate(); } + public int getBackgroundColor() { + return mBackgroundPaint.getColor(); + } + public void setColor(int newColor) { mColor = newColor; } @@ -76,6 +86,9 @@ public class MyCanvas extends View { protected void onDraw(Canvas canvas) { super.onDraw(canvas); + // Clear canvas background + canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint); + for (Map.Entry entry : mPaths.entrySet()) { mPaint.setColor(entry.getValue()); canvas.drawPath(entry.getKey(), mPaint); @@ -85,7 +98,9 @@ public class MyCanvas extends View { canvas.drawPath(mPath, mPaint); } - public void clearCanvas(){ + public void clearCanvas(int color) { + mBackgroundPaint.setColor(color); + mPath.reset(); mPaths.clear(); pathsUpdated(); diff --git a/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java index 63b9c00..b1ab380 100644 --- a/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java @@ -85,7 +85,19 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange startActivity(new Intent(getApplicationContext(), SettingsActivity.class)); return true; case R.id.clear: - mMyCanvas.clearCanvas(); + AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, mMyCanvas.getBackgroundColor(), + new AmbilWarnaDialog.OnAmbilWarnaListener() { + @Override + public void onCancel(AmbilWarnaDialog dialog) { + } + + @Override + public void onOk(AmbilWarnaDialog dialog, int pickedColor) { + mMyCanvas.clearCanvas(pickedColor); + } + }); + + dialog.show(); return true; case R.id.about: startActivity(new Intent(getApplicationContext(), AboutActivity.class));