android: cleanup
This commit is contained in:
parent
3a5c19f7d6
commit
17ac257f0c
6 changed files with 10 additions and 14 deletions
|
@ -39,6 +39,7 @@ import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
@ -162,8 +163,8 @@ class AppAdapterHandler(private val context: Context) : MethodCallHandler {
|
||||||
.submit(size, size)
|
.submit(size, size)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
val bitmap = withContext(Dispatchers.IO) { target.get() }
|
||||||
data = target.get()?.getBytes(canHaveAlpha = true, recycle = false)
|
data = bitmap?.getBytes(canHaveAlpha = true, recycle = false)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.w(LOG_TAG, "failed to decode app icon for packageName=$packageName", e)
|
Log.w(LOG_TAG, "failed to decode app icon for packageName=$packageName", e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,6 @@ class EmbeddedDataHandler(private val context: Context) : MethodCallHandler {
|
||||||
if (canReadWithExifInterface(mimeType)) {
|
if (canReadWithExifInterface(mimeType)) {
|
||||||
try {
|
try {
|
||||||
Metadata.openSafeInputStream(context, uri, mimeType, sizeBytes)?.use { input ->
|
Metadata.openSafeInputStream(context, uri, mimeType, sizeBytes)?.use { input ->
|
||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
|
||||||
val exif = ExifInterface(input)
|
val exif = ExifInterface(input)
|
||||||
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
|
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
|
||||||
exif.thumbnailBitmap?.let { bitmap ->
|
exif.thumbnailBitmap?.let { bitmap ->
|
||||||
|
|
|
@ -206,7 +206,6 @@ class ActivityResultStreamHandler(private val activity: Activity, arguments: Any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("SameParameterValue")
|
|
||||||
private fun error(errorCode: String, errorMessage: String, errorDetails: Any?) {
|
private fun error(errorCode: String, errorMessage: String, errorDetails: Any?) {
|
||||||
handler.post {
|
handler.post {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -28,6 +28,7 @@ import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
class ImageByteStreamHandler(private val context: Context, private val arguments: Any?) : EventChannel.StreamHandler {
|
class ImageByteStreamHandler(private val context: Context, private val arguments: Any?) : EventChannel.StreamHandler {
|
||||||
|
@ -144,8 +145,7 @@ class ImageByteStreamHandler(private val context: Context, private val arguments
|
||||||
.load(model)
|
.load(model)
|
||||||
.submit()
|
.submit()
|
||||||
try {
|
try {
|
||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
var bitmap = withContext(Dispatchers.IO) { target.get() }
|
||||||
var bitmap = target.get()
|
|
||||||
if (needRotationAfterGlide(mimeType)) {
|
if (needRotationAfterGlide(mimeType)) {
|
||||||
bitmap = applyExifOrientation(context, bitmap, rotationDegrees, isFlipped)
|
bitmap = applyExifOrientation(context, bitmap, rotationDegrees, isFlipped)
|
||||||
}
|
}
|
||||||
|
@ -173,8 +173,7 @@ class ImageByteStreamHandler(private val context: Context, private val arguments
|
||||||
.load(VideoThumbnail(context, uri))
|
.load(VideoThumbnail(context, uri))
|
||||||
.submit()
|
.submit()
|
||||||
try {
|
try {
|
||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
val bitmap = withContext(Dispatchers.IO) { target.get() }
|
||||||
val bitmap = target.get()
|
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
val bytes = bitmap.getBytes(canHaveAlpha = false, recycle = false)
|
val bytes = bitmap.getBytes(canHaveAlpha = false, recycle = false)
|
||||||
if (MemoryUtils.canAllocate(sizeBytes)) {
|
if (MemoryUtils.canAllocate(sizeBytes)) {
|
||||||
|
|
|
@ -45,6 +45,8 @@ import deckers.thibault.aves.utils.MimeTypes.canReadWithPixyMeta
|
||||||
import deckers.thibault.aves.utils.MimeTypes.canRemoveMetadata
|
import deckers.thibault.aves.utils.MimeTypes.canRemoveMetadata
|
||||||
import deckers.thibault.aves.utils.MimeTypes.extensionFor
|
import deckers.thibault.aves.utils.MimeTypes.extensionFor
|
||||||
import deckers.thibault.aves.utils.MimeTypes.isVideo
|
import deckers.thibault.aves.utils.MimeTypes.isVideo
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import pixy.meta.meta.Metadata
|
import pixy.meta.meta.Metadata
|
||||||
import pixy.meta.meta.MetadataType
|
import pixy.meta.meta.MetadataType
|
||||||
import java.io.*
|
import java.io.*
|
||||||
|
@ -308,8 +310,7 @@ abstract class ImageProvider {
|
||||||
.apply(glideOptions)
|
.apply(glideOptions)
|
||||||
.load(model)
|
.load(model)
|
||||||
.submit(targetWidthPx, targetHeightPx)
|
.submit(targetWidthPx, targetHeightPx)
|
||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
var bitmap = withContext(Dispatchers.IO) { target.get() }
|
||||||
var bitmap = target.get()
|
|
||||||
if (MimeTypes.needRotationAfterGlide(sourceMimeType)) {
|
if (MimeTypes.needRotationAfterGlide(sourceMimeType)) {
|
||||||
bitmap = BitmapUtils.applyExifOrientation(activity, bitmap, sourceEntry.rotationDegrees, sourceEntry.isFlipped)
|
bitmap = BitmapUtils.applyExifOrientation(activity, bitmap, sourceEntry.rotationDegrees, sourceEntry.isFlipped)
|
||||||
}
|
}
|
||||||
|
@ -457,7 +458,6 @@ abstract class ImageProvider {
|
||||||
editableFile.delete()
|
editableFile.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
|
||||||
suspend fun captureFrame(
|
suspend fun captureFrame(
|
||||||
contextWrapper: ContextWrapper,
|
contextWrapper: ContextWrapper,
|
||||||
desiredNameWithoutExtension: String,
|
desiredNameWithoutExtension: String,
|
||||||
|
@ -512,7 +512,7 @@ abstract class ImageProvider {
|
||||||
output.write(bytes)
|
output.write(bytes)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val editableFile = File.createTempFile("aves", null).apply {
|
val editableFile = withContext(Dispatchers.IO) { File.createTempFile("aves", null) }.apply {
|
||||||
deleteOnExit()
|
deleteOnExit()
|
||||||
transferFrom(ByteArrayInputStream(bytes), bytes.size.toLong())
|
transferFrom(ByteArrayInputStream(bytes), bytes.size.toLong())
|
||||||
}
|
}
|
||||||
|
|
|
@ -328,7 +328,6 @@ class MediaStoreImageProvider : ImageProvider() {
|
||||||
Log.d(LOG_TAG, "delete [permission:doc, file exists after content delete] document at uri=$uri path=$path")
|
Log.d(LOG_TAG, "delete [permission:doc, file exists after content delete] document at uri=$uri path=$path")
|
||||||
val df = StorageUtils.getDocumentFile(contextWrapper, path, uri)
|
val df = StorageUtils.getDocumentFile(contextWrapper, path, uri)
|
||||||
|
|
||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
|
||||||
if (df != null && df.delete()) {
|
if (df != null && df.delete()) {
|
||||||
scanObsoletePath(contextWrapper, uri, path, mimeType)
|
scanObsoletePath(contextWrapper, uri, path, mimeType)
|
||||||
return
|
return
|
||||||
|
@ -726,7 +725,6 @@ class MediaStoreImageProvider : ImageProvider() {
|
||||||
val df = StorageUtils.getDocumentFile(activity, oldPath, oldMediaUri)
|
val df = StorageUtils.getDocumentFile(activity, oldPath, oldMediaUri)
|
||||||
df ?: throw Exception("failed to get document at path=$oldPath")
|
df ?: throw Exception("failed to get document at path=$oldPath")
|
||||||
|
|
||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
|
||||||
val renamed = df.renameTo(newFile.name)
|
val renamed = df.renameTo(newFile.name)
|
||||||
if (!renamed) {
|
if (!renamed) {
|
||||||
throw Exception("failed to rename document at path=$oldPath")
|
throw Exception("failed to rename document at path=$oldPath")
|
||||||
|
|
Loading…
Reference in a new issue