adding an Undo button to editor drawing

This commit is contained in:
tibbi 2019-01-13 18:02:06 +01:00
parent 5f9378135a
commit 1776ab592d
3 changed files with 30 additions and 3 deletions

View File

@ -460,6 +460,10 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
config.lastEditorBrushSize = it
updateBrushSize(it)
}
bottom_draw_undo.setOnClickListener {
editor_draw_canvas.undo()
}
}
private fun updateBrushSize(percent: Int) {

View File

@ -139,4 +139,14 @@ class EditorDrawCanvas(context: Context, attrs: AttributeSet) : View(context, at
draw(canvas)
return bitmap
}
fun undo() {
if (mPaths.isEmpty()) {
return
}
val lastKey = mPaths.keys.lastOrNull()
mPaths.remove(lastKey)
invalidate()
}
}

View File

@ -24,21 +24,34 @@
android:id="@+id/bottom_draw_color_clickable"
android:layout_width="@dimen/bottom_editor_color_picker_size"
android:layout_height="@dimen/bottom_editor_color_picker_size"
android:layout_marginRight="@dimen/activity_margin"
android:layout_marginRight="@dimen/small_margin"
android:background="?attr/selectableItemBackgroundBorderless"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintRight_toLeftOf="@+id/bottom_draw_undo"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:id="@+id/bottom_draw_color"
android:layout_width="@dimen/bottom_editor_color_picker_size"
android:layout_height="@dimen/bottom_editor_color_picker_size"
android:layout_marginRight="@dimen/activity_margin"
android:layout_marginRight="@dimen/small_margin"
android:clickable="false"
android:padding="@dimen/small_margin"
android:src="@drawable/circle_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/bottom_draw_undo"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:id="@+id/bottom_draw_undo"
android:layout_width="@dimen/bottom_editor_color_picker_size"
android:layout_height="@dimen/bottom_editor_color_picker_size"
android:layout_marginRight="@dimen/normal_margin"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="false"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_undo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>