Added clear canvas functionality

Method "clearCanvas" added to class MyCanvas. It will clear the path list and update the canvas status on screen.
This commit is contained in:
Adrian Moreno 2016-07-26 17:56:18 +02:00
parent 28b3cf2ffc
commit b08d925d87
4 changed files with 15 additions and 0 deletions

View File

@ -85,6 +85,13 @@ public class MyCanvas extends View {
canvas.drawPath(mPath, mPaint);
}
public void clearCanvas(){
mPath = new Path();
mPaths = new LinkedHashMap<>();
pathsUpdated();
invalidate();
}
private void actionDown(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);

View File

@ -84,6 +84,9 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
case R.id.settings:
startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
return true;
case R.id.clear:
mMyCanvas.clearCanvas();
return true;
case R.id.about:
startActivity(new Intent(getApplicationContext(), AboutActivity.class));
return true;

View File

@ -15,6 +15,10 @@
android:id="@+id/settings"
android:title="@string/settings"
app:showAsAction="never"/>
<item
android:id="@+id/clear"
android:title="@string/clear"
app:showAsAction="never"/>
<item
android:id="@+id/about"
android:title="@string/about"

View File

@ -12,6 +12,7 @@
<!-- Settings -->
<string name="settings">Settings</string>
<string name="clear">Clear</string>
<string name="dark_theme">Dark theme</string>
<!-- About -->