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.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.math.roundToInt
|
||||
|
@ -162,8 +163,8 @@ class AppAdapterHandler(private val context: Context) : MethodCallHandler {
|
|||
.submit(size, size)
|
||||
|
||||
try {
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
data = target.get()?.getBytes(canHaveAlpha = true, recycle = false)
|
||||
val bitmap = withContext(Dispatchers.IO) { target.get() }
|
||||
data = bitmap?.getBytes(canHaveAlpha = true, recycle = false)
|
||||
} catch (e: Exception) {
|
||||
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)) {
|
||||
try {
|
||||
Metadata.openSafeInputStream(context, uri, mimeType, sizeBytes)?.use { input ->
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
val exif = ExifInterface(input)
|
||||
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
|
||||
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?) {
|
||||
handler.post {
|
||||
try {
|
||||
|
|
|
@ -28,6 +28,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.InputStream
|
||||
|
||||
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)
|
||||
.submit()
|
||||
try {
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
var bitmap = target.get()
|
||||
var bitmap = withContext(Dispatchers.IO) { target.get() }
|
||||
if (needRotationAfterGlide(mimeType)) {
|
||||
bitmap = applyExifOrientation(context, bitmap, rotationDegrees, isFlipped)
|
||||
}
|
||||
|
@ -173,8 +173,7 @@ class ImageByteStreamHandler(private val context: Context, private val arguments
|
|||
.load(VideoThumbnail(context, uri))
|
||||
.submit()
|
||||
try {
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
val bitmap = target.get()
|
||||
val bitmap = withContext(Dispatchers.IO) { target.get() }
|
||||
if (bitmap != null) {
|
||||
val bytes = bitmap.getBytes(canHaveAlpha = false, recycle = false)
|
||||
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.extensionFor
|
||||
import deckers.thibault.aves.utils.MimeTypes.isVideo
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import pixy.meta.meta.Metadata
|
||||
import pixy.meta.meta.MetadataType
|
||||
import java.io.*
|
||||
|
@ -308,8 +310,7 @@ abstract class ImageProvider {
|
|||
.apply(glideOptions)
|
||||
.load(model)
|
||||
.submit(targetWidthPx, targetHeightPx)
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
var bitmap = target.get()
|
||||
var bitmap = withContext(Dispatchers.IO) { target.get() }
|
||||
if (MimeTypes.needRotationAfterGlide(sourceMimeType)) {
|
||||
bitmap = BitmapUtils.applyExifOrientation(activity, bitmap, sourceEntry.rotationDegrees, sourceEntry.isFlipped)
|
||||
}
|
||||
|
@ -457,7 +458,6 @@ abstract class ImageProvider {
|
|||
editableFile.delete()
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
suspend fun captureFrame(
|
||||
contextWrapper: ContextWrapper,
|
||||
desiredNameWithoutExtension: String,
|
||||
|
@ -512,7 +512,7 @@ abstract class ImageProvider {
|
|||
output.write(bytes)
|
||||
}
|
||||
} else {
|
||||
val editableFile = File.createTempFile("aves", null).apply {
|
||||
val editableFile = withContext(Dispatchers.IO) { File.createTempFile("aves", null) }.apply {
|
||||
deleteOnExit()
|
||||
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")
|
||||
val df = StorageUtils.getDocumentFile(contextWrapper, path, uri)
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
if (df != null && df.delete()) {
|
||||
scanObsoletePath(contextWrapper, uri, path, mimeType)
|
||||
return
|
||||
|
@ -726,7 +725,6 @@ class MediaStoreImageProvider : ImageProvider() {
|
|||
val df = StorageUtils.getDocumentFile(activity, oldPath, oldMediaUri)
|
||||
df ?: throw Exception("failed to get document at path=$oldPath")
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
val renamed = df.renameTo(newFile.name)
|
||||
if (!renamed) {
|
||||
throw Exception("failed to rename document at path=$oldPath")
|
||||
|
|
Loading…
Reference in a new issue