mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-02-20 05:30:57 +01:00
Added clear color (implements and closes #6)
This commit is contained in:
parent
749fd2ae9d
commit
9a90f8db00
@ -14,6 +14,8 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MyCanvas extends View {
|
public class MyCanvas extends View {
|
||||||
|
private Paint mBackgroundPaint;
|
||||||
|
|
||||||
private Paint mPaint;
|
private Paint mPaint;
|
||||||
private Path mPath;
|
private Path mPath;
|
||||||
private Map<Path, Integer> mPaths;
|
private Map<Path, Integer> mPaths;
|
||||||
@ -28,6 +30,10 @@ public class MyCanvas extends View {
|
|||||||
public MyCanvas(Context context, AttributeSet attrs) {
|
public MyCanvas(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
|
||||||
|
mBackgroundPaint = new Paint();
|
||||||
|
mBackgroundPaint.setColor(Color.WHITE);
|
||||||
|
mBackgroundPaint.setStyle(Paint.Style.FILL);
|
||||||
|
|
||||||
mPath = new Path();
|
mPath = new Path();
|
||||||
mPaint = new Paint();
|
mPaint = new Paint();
|
||||||
mPaint.setColor(Color.BLACK);
|
mPaint.setColor(Color.BLACK);
|
||||||
@ -60,6 +66,10 @@ public class MyCanvas extends View {
|
|||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getBackgroundColor() {
|
||||||
|
return mBackgroundPaint.getColor();
|
||||||
|
}
|
||||||
|
|
||||||
public void setColor(int newColor) {
|
public void setColor(int newColor) {
|
||||||
mColor = newColor;
|
mColor = newColor;
|
||||||
}
|
}
|
||||||
@ -76,6 +86,9 @@ public class MyCanvas extends View {
|
|||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
|
|
||||||
|
// Clear canvas background
|
||||||
|
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint);
|
||||||
|
|
||||||
for (Map.Entry<Path, Integer> entry : mPaths.entrySet()) {
|
for (Map.Entry<Path, Integer> entry : mPaths.entrySet()) {
|
||||||
mPaint.setColor(entry.getValue());
|
mPaint.setColor(entry.getValue());
|
||||||
canvas.drawPath(entry.getKey(), mPaint);
|
canvas.drawPath(entry.getKey(), mPaint);
|
||||||
@ -85,7 +98,9 @@ public class MyCanvas extends View {
|
|||||||
canvas.drawPath(mPath, mPaint);
|
canvas.drawPath(mPath, mPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearCanvas(){
|
public void clearCanvas(int color) {
|
||||||
|
mBackgroundPaint.setColor(color);
|
||||||
|
|
||||||
mPath.reset();
|
mPath.reset();
|
||||||
mPaths.clear();
|
mPaths.clear();
|
||||||
pathsUpdated();
|
pathsUpdated();
|
||||||
|
@ -85,7 +85,19 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
|
|||||||
startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
|
startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
|
||||||
return true;
|
return true;
|
||||||
case R.id.clear:
|
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;
|
return true;
|
||||||
case R.id.about:
|
case R.id.about:
|
||||||
startActivity(new Intent(getApplicationContext(), AboutActivity.class));
|
startActivity(new Intent(getApplicationContext(), AboutActivity.class));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user