mirror of
https://github.com/tabidachinokaze/Electro.git
synced 2026-03-01 11:59:44 +08:00
修复bug
This commit is contained in:
@@ -4,7 +4,6 @@ import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.getValue
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package cn.tabidachi.electro.coil
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.HardwareRenderer
|
||||
import android.graphics.PixelFormat
|
||||
import android.graphics.RenderEffect
|
||||
import android.graphics.RenderNode
|
||||
import android.graphics.Shader
|
||||
import android.hardware.HardwareBuffer
|
||||
import android.media.ImageReader
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import coil.size.Size
|
||||
import coil.transform.Transformation
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.S)
|
||||
class BlurTransformation(
|
||||
private val radius: Float,
|
||||
private val sampling: Float
|
||||
) : Transformation {
|
||||
override val cacheKey: String = "${BlurTransformation::class.java.name}-$radius-$sampling"
|
||||
|
||||
@SuppressLint("WrongConstant")
|
||||
override suspend fun transform(input: Bitmap, size: Size): Bitmap {
|
||||
val renderNode = RenderNode("RenderEffect")
|
||||
val hardwareRenderer = HardwareRenderer()
|
||||
val imageReader = ImageReader.newInstance(
|
||||
input.width,
|
||||
input.height,
|
||||
PixelFormat.RGBA_8888,
|
||||
1,
|
||||
HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE or HardwareBuffer.USAGE_GPU_COLOR_OUTPUT
|
||||
)
|
||||
hardwareRenderer.setSurface(imageReader.surface)
|
||||
hardwareRenderer.setContentRoot(renderNode)
|
||||
renderNode.setPosition(0, 0, imageReader.width, imageReader.height)
|
||||
val blurEffect = RenderEffect.createBlurEffect(radius, radius, Shader.TileMode.MIRROR)
|
||||
renderNode.setRenderEffect(blurEffect)
|
||||
val recordingCanvas = renderNode.beginRecording()
|
||||
recordingCanvas.drawBitmap(input, 0f, 0f, null)
|
||||
renderNode.endRecording()
|
||||
hardwareRenderer.createRenderRequest()
|
||||
.setWaitForPresent(true)
|
||||
.syncAndDraw()
|
||||
val image = imageReader.acquireNextImage() ?: throw RuntimeException("No Image")
|
||||
val hardwareBuffer = image.hardwareBuffer ?: throw RuntimeException("No HardwareBuffer")
|
||||
val bitmap = Bitmap.wrapHardwareBuffer(hardwareBuffer, null)
|
||||
?: throw RuntimeException("Create bitmap Failed")
|
||||
hardwareBuffer.close()
|
||||
image.close()
|
||||
imageReader.close()
|
||||
renderNode.discardDisplayList()
|
||||
hardwareRenderer.destroy()
|
||||
return bitmap
|
||||
}
|
||||
}
|
||||
@@ -175,10 +175,10 @@ class Ktor(
|
||||
.header("Authorization", "Bearer $token")
|
||||
.build()
|
||||
okHttpClient.newCall(request).execute()
|
||||
client.get(url) {
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody(Any())
|
||||
}
|
||||
// client.get(url) {
|
||||
// contentType(ContentType.Application.Json)
|
||||
// setBody(Any())
|
||||
// }
|
||||
}.onFailure {
|
||||
Log.e(TAG, "get: $url", it)
|
||||
}.mapCatching {
|
||||
|
||||
@@ -53,7 +53,7 @@ private object ElectroScreens {
|
||||
const val GROUP_ADMIN_SCREEN = "group_admin"
|
||||
const val CHANNEL_SCREEN = "channel"
|
||||
const val CHANNEL_CREATE_SCREEN = "channel_create"
|
||||
const val CHANNEL_ADMIN_SCREEN = "group_admin"
|
||||
const val CHANNEL_ADMIN_SCREEN = "channel_admin"
|
||||
const val CHANNEL_DETAIL_SCREEN = "channel_detail"
|
||||
const val CHANNEL_INVITE_SCREEN = "channel_invite"
|
||||
const val CHANNEL_EDIT_SCREEN = "channel_edit"
|
||||
|
||||
@@ -14,7 +14,6 @@ import android.util.Pair
|
||||
import android.view.View
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -42,6 +41,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.core.view.ContentInfoCompat
|
||||
import androidx.core.view.OnReceiveContentListener
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import cn.tabidachi.electro.coil.BlurTransformation
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import cn.tabidachi.electro.LocationActivity
|
||||
@@ -73,7 +73,6 @@ import coil.request.ImageRequest
|
||||
import coil.size.Scale
|
||||
import com.amap.api.maps.model.LatLng
|
||||
import com.amap.api.services.core.PoiItemV2
|
||||
import com.commit451.coiltransformations.BlurTransformation
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.util.generateNonce
|
||||
@@ -462,9 +461,14 @@ class MessageViewModel @Inject constructor(
|
||||
private fun blur(bitmap: Bitmap): Bitmap {
|
||||
val request = ImageRequest.Builder(application)
|
||||
.data(bitmap)
|
||||
.transformations(BlurTransformation(application, 25f))
|
||||
.transformations(BlurTransformation(25f, 1f))
|
||||
.build()
|
||||
return (application.imageLoader.executeBlocking(request).drawable as BitmapDrawable).bitmap
|
||||
return (application.imageLoader.executeBlocking(request).drawable.also {
|
||||
println("Drawable $it")
|
||||
} as BitmapDrawable).bitmap.copy(
|
||||
Bitmap.Config.ARGB_8888,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
private fun quality(bitmap: Bitmap): ByteArray {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
buildscript {
|
||||
ext {
|
||||
compose_bom_version = '2023.05.00'
|
||||
compose_bom_version = '2023.06.00'
|
||||
ktor_version = '2.3.0'
|
||||
}
|
||||
}
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id 'com.android.application' version '8.0.1' apply false
|
||||
id 'com.android.library' version '8.0.1' apply false
|
||||
id 'com.android.application' version '8.0.2' apply false
|
||||
id 'com.android.library' version '8.0.2' apply false
|
||||
id 'org.jetbrains.kotlin.android' version '1.8.21' apply false
|
||||
id 'com.google.dagger.hilt.android' version '2.46.1' apply false
|
||||
id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.21' apply false
|
||||
|
||||
Reference in New Issue
Block a user