update commons to 3.13.9
This commit is contained in:
parent
0765a67caf
commit
7ae84cf087
|
@ -45,7 +45,7 @@ ext {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:3.11.6'
|
implementation 'com.simplemobiletools:commons:3.13.9'
|
||||||
|
|
||||||
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
|
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
|
||||||
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
|
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
|
||||||
|
|
|
@ -18,6 +18,7 @@ import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
|
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
|
||||||
import com.simplemobiletools.commons.helpers.LICENSE_LEAK_CANARY
|
import com.simplemobiletools.commons.helpers.LICENSE_LEAK_CANARY
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||||
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.commons.models.Release
|
import com.simplemobiletools.commons.models.Release
|
||||||
import com.simplemobiletools.draw.BuildConfig
|
import com.simplemobiletools.draw.BuildConfig
|
||||||
import com.simplemobiletools.draw.R
|
import com.simplemobiletools.draw.R
|
||||||
|
@ -31,7 +32,6 @@ import com.simplemobiletools.draw.models.Svg
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), CanvasListener {
|
class MainActivity : SimpleActivity(), CanvasListener {
|
||||||
|
@ -176,7 +176,7 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
||||||
|
|
||||||
if (intent?.action == Intent.ACTION_VIEW && intent.data != null) {
|
if (intent?.action == Intent.ACTION_VIEW && intent.data != null) {
|
||||||
getStoragePermission {
|
getStoragePermission {
|
||||||
val path = intent.data.path
|
val path = getRealPathFromURI(intent.data) ?: intent.dataString
|
||||||
openPath(path)
|
openPath(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,14 +267,14 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun confirmImage() {
|
private fun confirmImage() {
|
||||||
val file = File(defaultPath)
|
|
||||||
if (intentUri?.scheme == "content") {
|
if (intentUri?.scheme == "content") {
|
||||||
val outputStream = contentResolver.openOutputStream(intentUri)
|
val outputStream = contentResolver.openOutputStream(intentUri)
|
||||||
saveToOutputStream(outputStream, file.getCompressionFormat())
|
saveToOutputStream(outputStream, defaultPath.getCompressionFormat())
|
||||||
} else {
|
} else {
|
||||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||||
getFileOutputStream(file) {
|
val fileDirItem = FileDirItem(defaultPath, defaultPath.getFilenameFromPath())
|
||||||
saveToOutputStream(it, file.getCompressionFormat())
|
getFileOutputStream(fileDirItem, true) {
|
||||||
|
saveToOutputStream(it, defaultPath.getCompressionFormat())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -310,36 +310,39 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun shareImage() {
|
private fun shareImage() {
|
||||||
val uri = getImageUri(my_canvas.getBitmap())
|
getImagePath(my_canvas.getBitmap()) {
|
||||||
if (uri != null) {
|
if (it != null) {
|
||||||
shareUri(uri, BuildConfig.APPLICATION_ID)
|
sharePathIntent(it, BuildConfig.APPLICATION_ID)
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getImageUri(bitmap: Bitmap): Uri? {
|
private fun getImagePath(bitmap: Bitmap, callback: (path: String?) -> Unit) {
|
||||||
val bytes = ByteArrayOutputStream()
|
val bytes = ByteArrayOutputStream()
|
||||||
bitmap.compress(Bitmap.CompressFormat.PNG, 0, bytes)
|
bitmap.compress(Bitmap.CompressFormat.PNG, 0, bytes)
|
||||||
|
|
||||||
val folder = File(cacheDir, FOLDER_NAME)
|
val folder = File(cacheDir, FOLDER_NAME)
|
||||||
if (!folder.exists()) {
|
if (!folder.exists()) {
|
||||||
if (!folder.mkdir()) {
|
if (!folder.mkdir()) {
|
||||||
return null
|
callback(null)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val file = File(folder, FILE_NAME)
|
val newPath = "$folder/$FILE_NAME"
|
||||||
var fileOutputStream: FileOutputStream? = null
|
val fileDirItem = FileDirItem(newPath, FILE_NAME)
|
||||||
|
getFileOutputStream(fileDirItem, true) {
|
||||||
try {
|
try {
|
||||||
fileOutputStream = FileOutputStream(file)
|
it?.write(bytes.toByteArray())
|
||||||
fileOutputStream.write(bytes.toByteArray())
|
callback(newPath)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
} finally {
|
} finally {
|
||||||
fileOutputStream?.close()
|
it?.close()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return getFilePublicUri(file, BuildConfig.APPLICATION_ID)
|
callback("")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun clearCanvas() {
|
private fun clearCanvas() {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.support.v7.app.AlertDialog
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.draw.R
|
import com.simplemobiletools.draw.R
|
||||||
import com.simplemobiletools.draw.activities.SimpleActivity
|
import com.simplemobiletools.draw.activities.SimpleActivity
|
||||||
import com.simplemobiletools.draw.helpers.JPG
|
import com.simplemobiletools.draw.helpers.JPG
|
||||||
|
@ -84,22 +85,23 @@ class SaveImageDialog(val activity: SimpleActivity, val defaultExtension: String
|
||||||
|
|
||||||
when (file.extension) {
|
when (file.extension) {
|
||||||
SVG -> Svg.saveSvg(activity, file, canvas)
|
SVG -> Svg.saveSvg(activity, file, canvas)
|
||||||
else -> saveImageFile(file)
|
else -> saveImageFile(file.absolutePath)
|
||||||
}
|
}
|
||||||
activity.scanFile(file) {}
|
activity.scanFile(file) {}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveImageFile(file: File) {
|
private fun saveImageFile(path: String) {
|
||||||
activity.getFileOutputStream(file) {
|
val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
|
||||||
writeToOutputStream(file, it!!)
|
activity.getFileOutputStream(fileDirItem, true) {
|
||||||
|
writeToOutputStream(path, it!!)
|
||||||
activity.toast(R.string.file_saved)
|
activity.toast(R.string.file_saved)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writeToOutputStream(file: File, out: OutputStream) {
|
private fun writeToOutputStream(path: String, out: OutputStream) {
|
||||||
out.use {
|
out.use {
|
||||||
canvas.getBitmap().compress(file.getCompressionFormat(), 70, out)
|
canvas.getBitmap().compress(path.getCompressionFormat(), 70, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,12 @@ import android.net.Uri
|
||||||
import android.sax.RootElement
|
import android.sax.RootElement
|
||||||
import android.util.Xml
|
import android.util.Xml
|
||||||
import com.simplemobiletools.commons.extensions.getFileOutputStream
|
import com.simplemobiletools.commons.extensions.getFileOutputStream
|
||||||
|
import com.simplemobiletools.commons.extensions.toFileDirItem
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.draw.views.MyCanvas
|
|
||||||
import com.simplemobiletools.draw.R
|
import com.simplemobiletools.draw.R
|
||||||
import com.simplemobiletools.draw.activities.MainActivity
|
import com.simplemobiletools.draw.activities.MainActivity
|
||||||
import com.simplemobiletools.draw.activities.SimpleActivity
|
import com.simplemobiletools.draw.activities.SimpleActivity
|
||||||
|
import com.simplemobiletools.draw.views.MyCanvas
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ object Svg {
|
||||||
fun saveSvg(activity: SimpleActivity, file: File, canvas: MyCanvas) {
|
fun saveSvg(activity: SimpleActivity, file: File, canvas: MyCanvas) {
|
||||||
val backgroundColor = (canvas.background as ColorDrawable).color
|
val backgroundColor = (canvas.background as ColorDrawable).color
|
||||||
|
|
||||||
activity.getFileOutputStream(file) {
|
activity.getFileOutputStream(file.toFileDirItem(activity), true) {
|
||||||
val writer = BufferedWriter(OutputStreamWriter(it))
|
val writer = BufferedWriter(OutputStreamWriter(it))
|
||||||
writeSvg(writer, backgroundColor, canvas.mPaths, canvas.width, canvas.height)
|
writeSvg(writer, backgroundColor, canvas.mPaths, canvas.width, canvas.height)
|
||||||
writer.close()
|
writer.close()
|
||||||
|
|
Loading…
Reference in New Issue