Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Adding an Eraser and Starting a New Drawing
- Loading branch information
|
@@ -73,4 +73,11 @@ public void setCurrentColor(int color) { |
|
|
public void setCurrentWidth(int width) { |
|
|
currentWidth = (width + 1) * 2; |
|
|
} |
|
|
|
|
|
public void erase() { |
|
|
paths.clear(); |
|
|
colors.clear(); |
|
|
widths.clear(); |
|
|
invalidate(); |
|
|
} |
|
|
} |
|
|
@@ -1,6 +1,8 @@ |
|
|
package com.dragosholban.androiddrawing; |
|
|
|
|
|
import android.content.DialogInterface; |
|
|
import android.graphics.drawable.ColorDrawable; |
|
|
import android.support.v7.app.AlertDialog; |
|
|
import android.support.v7.app.AppCompatActivity; |
|
|
import android.os.Bundle; |
|
|
import android.view.View; |
|
@@ -41,5 +43,28 @@ public void onStopTrackingTouch(SeekBar seekBar) { |
|
|
public void setColor(View view) { |
|
|
ColorDrawable buttonColor = (ColorDrawable) view.getBackground(); |
|
|
drawingView.setCurrentColor(buttonColor.getColor()); |
|
|
if (view.getTag() != null && view.getTag().equals("eraser")) { |
|
|
drawingView.setCurrentWidth(seekBar.getProgress() * 4); |
|
|
} else { |
|
|
drawingView.setCurrentWidth(seekBar.getProgress()); |
|
|
} |
|
|
} |
|
|
|
|
|
public void deleteDrawing(View view) { |
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
|
|
builder.setMessage("Are you sure you want to erase everything?") |
|
|
.setTitle("Delete Drawing") |
|
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
|
|
public void onClick(DialogInterface dialog, int id) { |
|
|
drawingView.erase(); |
|
|
} |
|
|
}) |
|
|
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
|
|
public void onClick(DialogInterface dialog, int id) { |
|
|
|
|
|
} |
|
|
}); |
|
|
AlertDialog dialog = builder.create(); |
|
|
dialog.show(); |
|
|
} |
|
|
} |
|
@@ -62,6 +62,21 @@ |
|
|
android:layout_margin="1dp" |
|
|
android:background="#000000" |
|
|
android:onClick="setColor"/> |
|
|
<View |
|
|
android:layout_width="0dp" |
|
|
android:layout_height="match_parent" |
|
|
android:layout_weight="1" |
|
|
android:layout_margin="1dp" |
|
|
android:background="#FFFFFF" |
|
|
android:onClick="setColor" |
|
|
android:tag="eraser"/> |
|
|
<Button |
|
|
android:id="@+id/button" |
|
|
android:layout_width="0dp" |
|
|
android:layout_height="wrap_content" |
|
|
android:layout_weight="1" |
|
|
android:background="@android:drawable/ic_menu_delete" |
|
|
android:onClick="deleteDrawing" /> |
|
|
</LinearLayout> |
|
|
<SeekBar |
|
|
android:id="@+id/seekBar" |
|
|