-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
179 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# CHANGELOG | ||
|
||
## 1.4.0 (2022-04-29) | ||
* add `DrawingViewState` containing all the needed information to draw image on canvas | ||
* bump Kotlin to 1.6.21, Gradle plugin to 7.1.3 | ||
* bump buildToolsVersion to 32.0.0, compileSdkVersion and targetSdkVersion to 32 | ||
|
||
## 1.3.0 (2020-08-05) | ||
* bump Gradle plugin to 7.0.0 | ||
* update publish scripts | ||
|
||
## 1.2.0 (2021-03-24) | ||
* add `undoAll()`, `redoAll()`, `clearRedoHistory()`, `isDrawingEmpty()` | ||
* add explicit callbacks parameter names to `listenerEmptyState` and `listenerDrawingInProgress` | ||
* add option to define canvas colour | ||
* remove reference to additional canvas | ||
* better documentation of public methods and parameters | ||
|
||
## 1.1.0 (2021-03-23) | ||
* add `sizeChanged` flag to determine when to create new canvas instead of creating it from | ||
bitmap on every size change | ||
* bump Kotlin to 1.4.31, Gradle plugin to 4.1.3, Build tools to 30.0.3 | ||
|
||
## 1.0.2 (2020-12-05) | ||
* add documentation | ||
* remove deprecated Kotlin extensions from example app | ||
* bump to Kotlin 1.4.20 and Gradle plugin 4.1.1 | ||
|
||
## 1.0.1 (2020-08-24) | ||
* add license | ||
* bump Kotlin to 1.4.0, Gradle plugin to 4.0.1 and build tools to 30.0.2 | ||
|
||
## 1.0.0 (2020-05-26) | ||
* initial public release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
drawingview/src/main/kotlin/com/vojtkovszky/drawingview/DrawingViewState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.vojtkovszky.drawingview | ||
|
||
import android.graphics.Paint | ||
import android.graphics.Path | ||
import java.io.Serializable | ||
|
||
/** | ||
* Class holding all the necessary information required to draw paths and paints | ||
* on the canvas. | ||
*/ | ||
class DrawingViewState: Serializable { | ||
|
||
private val drawPathHistory = mutableListOf<Path>() | ||
private val drawPaintHistory = mutableListOf<Paint>() | ||
private val undonePaths = mutableListOf<Path>() | ||
private val undonePaints = mutableListOf<Paint>() | ||
|
||
// add path and paint to history | ||
internal fun addToHistory(path: Path, paint: Paint) { | ||
drawPathHistory.add(path) | ||
drawPaintHistory.add(Paint(paint)) | ||
} | ||
|
||
// clears redo history by cleaning undone paths and paints | ||
internal fun clearRedoHistory() { | ||
undonePaths.clear() | ||
undonePaints.clear() | ||
} | ||
|
||
// return single path from history on index | ||
internal fun getPathFromHistory(index: Int): Path { | ||
return drawPathHistory[index] | ||
} | ||
|
||
// return single paint from history on index | ||
internal fun getPaintFromHistory(index: Int): Paint { | ||
return drawPaintHistory[index] | ||
} | ||
|
||
// return number of available undone steps | ||
internal fun numUndoneSteps(): Int { | ||
return undonePaths.size | ||
} | ||
|
||
// return number of available history steps | ||
internal fun numHistorySteps(): Int { | ||
return drawPathHistory.size | ||
} | ||
|
||
// moves latest path and pant from undone list to history list | ||
// by removing from undone list and adding to history list | ||
internal fun redo() { | ||
drawPathHistory.add(undonePaths.removeAt(undonePaths.size - 1)) | ||
drawPaintHistory.add(undonePaints.removeAt(undonePaints.size - 1)) | ||
} | ||
|
||
// reset the history and undone lists | ||
internal fun startNew() { | ||
drawPathHistory.clear() | ||
drawPaintHistory.clear() | ||
undonePaths.clear() | ||
undonePaints.clear() | ||
} | ||
|
||
// moves latest path and pant from history list to undone list | ||
// by removing from history list and adding to undone list | ||
internal fun undo() { | ||
undonePaths.add(drawPathHistory.removeAt(drawPathHistory.size - 1)) | ||
undonePaints.add(drawPaintHistory.removeAt(drawPaintHistory.size - 1)) | ||
} | ||
|
||
/** | ||
* Determine if we have any paths or paints in history | ||
*/ | ||
fun isHistoryEmpty(): Boolean { | ||
return drawPathHistory.isEmpty() //&& drawPaintHistory.isEmpty() | ||
} | ||
|
||
/** | ||
* Determine if we have any paths or paints in undo history | ||
*/ | ||
fun isUndoneEmpty(): Boolean { | ||
return undonePaths.isEmpty() //&& undonePaints.isEmpty() | ||
} | ||
} |
Oops, something went wrong.