diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e590c5d..b0ac41c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,6 +46,11 @@ + + + + + confirmImage() R.id.menu_save -> trySaveImage() R.id.menu_share -> shareImage() R.id.clear -> clearCanvas() @@ -105,17 +116,14 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener { } private fun tryOpenFile() { - handlePermission(PERMISSION_WRITE_STORAGE) { - if (it) { - openFile() - } else { - toast(R.string.no_storage_permissions) - } + getStoragePermission { + openFile() } } private fun openFile() { - FilePickerDialog(this, curPath) { + val path = if (isImageCaptureIntent) "" else curPath + FilePickerDialog(this, path) { openPath(it) } } @@ -141,6 +149,16 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener { openPath(path) } } + + if (intent?.action == MediaStore.ACTION_IMAGE_CAPTURE) { + val output = intent.extras?.get(MediaStore.EXTRA_OUTPUT) + if (output != null && output is Uri) { + isImageCaptureIntent = true + Log.e("DEBUG", "output $output, path ${output.path}") + curPath = output.path + invalidateOptionsMenu() + } + } } private fun getStoragePermission(callback: () -> Unit) { @@ -217,13 +235,20 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener { } } - private fun trySaveImage() { - handlePermission(PERMISSION_WRITE_STORAGE) { - if (it) { - saveImage() - } else { - toast(R.string.no_storage_permissions) + private fun confirmImage() { + val file = File(curPath) + getFileOutputStream(file) { + it.use { + my_canvas.getBitmap().compress(file.getCompressionFormat(), 70, it) } + setResult(Activity.RESULT_OK) + finish() + } + } + + private fun trySaveImage() { + getStoragePermission { + saveImage() } } diff --git a/app/src/main/res/menu/menu.xml b/app/src/main/res/menu/menu.xml index 48e2a86..8ff45ee 100644 --- a/app/src/main/res/menu/menu.xml +++ b/app/src/main/res/menu/menu.xml @@ -1,6 +1,11 @@ +