mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-05-23 22:24:23 +02:00
properly restore selected image on device rotation or background color change
This commit is contained in:
parent
b3a140658b
commit
a96e90cb70
@ -41,12 +41,14 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
|||||||
private val FOLDER_NAME = "images"
|
private val FOLDER_NAME = "images"
|
||||||
private val FILE_NAME = "simple-draw.png"
|
private val FILE_NAME = "simple-draw.png"
|
||||||
private val BITMAP_PATH = "bitmap_path"
|
private val BITMAP_PATH = "bitmap_path"
|
||||||
|
private val URI_TO_LOAD = "uri_to_load"
|
||||||
|
|
||||||
private var defaultPath = ""
|
private var defaultPath = ""
|
||||||
private var defaultFilename = ""
|
private var defaultFilename = ""
|
||||||
private var defaultExtension = PNG
|
private var defaultExtension = PNG
|
||||||
|
|
||||||
private var intentUri: Uri? = null
|
private var intentUri: Uri? = null
|
||||||
|
private var uriToLoad: Uri? = null
|
||||||
private var color = 0
|
private var color = 0
|
||||||
private var brushSize = 0f
|
private var brushSize = 0f
|
||||||
private var isEraserOn = false
|
private var isEraserOn = false
|
||||||
@ -220,8 +222,14 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun tryOpenUri(uri: Uri, intent: Intent) = when {
|
private fun tryOpenUri(uri: Uri, intent: Intent) = when {
|
||||||
uri.scheme == "file" -> openPath(uri.path)
|
uri.scheme == "file" -> {
|
||||||
uri.scheme == "content" -> openUri(uri, intent)
|
uriToLoad = uri
|
||||||
|
openPath(uri.path)
|
||||||
|
}
|
||||||
|
uri.scheme == "content" -> {
|
||||||
|
uriToLoad = uri
|
||||||
|
openUri(uri, intent)
|
||||||
|
}
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,6 +290,10 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
|||||||
if (wasPositivePressed) {
|
if (wasPositivePressed) {
|
||||||
config.canvasBackgroundColor = color
|
config.canvasBackgroundColor = color
|
||||||
setBackgroundColor(color)
|
setBackgroundColor(color)
|
||||||
|
|
||||||
|
if (uriToLoad != null) {
|
||||||
|
tryOpenUri(uriToLoad!!, intent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -399,6 +411,7 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun clearCanvas() {
|
private fun clearCanvas() {
|
||||||
|
uriToLoad = null
|
||||||
my_canvas.clearCanvas()
|
my_canvas.clearCanvas()
|
||||||
defaultExtension = PNG
|
defaultExtension = PNG
|
||||||
defaultPath = ""
|
defaultPath = ""
|
||||||
@ -447,6 +460,10 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
|||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
outState.putString(BITMAP_PATH, lastBitmapPath)
|
outState.putString(BITMAP_PATH, lastBitmapPath)
|
||||||
|
|
||||||
|
if (uriToLoad != null) {
|
||||||
|
outState.putString(URI_TO_LOAD, uriToLoad.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||||
@ -454,6 +471,9 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
|||||||
lastBitmapPath = savedInstanceState.getString(BITMAP_PATH)
|
lastBitmapPath = savedInstanceState.getString(BITMAP_PATH)
|
||||||
if (lastBitmapPath.isNotEmpty()) {
|
if (lastBitmapPath.isNotEmpty()) {
|
||||||
openPath(lastBitmapPath)
|
openPath(lastBitmapPath)
|
||||||
|
} else if (savedInstanceState.containsKey(URI_TO_LOAD)) {
|
||||||
|
uriToLoad = Uri.parse(savedInstanceState.getString(URI_TO_LOAD))
|
||||||
|
tryOpenUri(uriToLoad!!, intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user