mirror of
				https://github.com/SimpleMobileTools/Simple-Draw.git
				synced 2025-06-05 21:59:17 +02:00 
			
		
		
		
	Added clear color (implements and closes #6)
This commit is contained in:
		| @@ -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<Path, Integer> 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<Path, Integer> 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(); | ||||
|   | ||||
| @@ -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)); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user