From 7cb8b70cdb5f097a9b03ebdb7e1a00a20b242bff Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 12 Aug 2019 20:05:05 +0800 Subject: [PATCH] up --- .../io/legado/app/help/BlurTransformation.kt | 57 +++++++++++++++++++ .../app/ui/bookinfo/BookInfoActivity.kt | 2 +- .../app/ui/bookinfo/BookInfoViewModel.kt | 2 +- .../main/res/layout/activity_book_info.xml | 5 +- 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/io/legado/app/help/BlurTransformation.kt diff --git a/app/src/main/java/io/legado/app/help/BlurTransformation.kt b/app/src/main/java/io/legado/app/help/BlurTransformation.kt new file mode 100644 index 000000000..7cf8de88b --- /dev/null +++ b/app/src/main/java/io/legado/app/help/BlurTransformation.kt @@ -0,0 +1,57 @@ +package io.legado.app.help + +import android.annotation.TargetApi +import android.content.Context +import android.graphics.Bitmap +import android.os.Build +import android.renderscript.Allocation +import android.renderscript.Element +import android.renderscript.RenderScript +import android.renderscript.ScriptIntrinsicBlur + +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation + +import java.security.MessageDigest + +class BlurTransformation(context: Context, private val radius: Int) : BitmapTransformation() { + private val rs: RenderScript = RenderScript.create(context) + + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) + override fun transform(pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight: Int): Bitmap { + val blurredBitmap = toTransform.copy(Bitmap.Config.ARGB_8888, true) + + // Allocate memory for Renderscript to work with + //分配用于渲染脚本的内存 + val input = Allocation.createFromBitmap( + rs, + blurredBitmap, + Allocation.MipmapControl.MIPMAP_FULL, + Allocation.USAGE_SHARED + ) + val output = Allocation.createTyped(rs, input.type) + + // Load up an instance of the specific script that we want to use. + //加载我们想要使用的特定脚本的实例。 + val script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)) + script.setInput(input) + + // Set the blur radius + //设置模糊半径 + script.setRadius(radius.toFloat()) + + // Start the ScriptIntrinsicBlur + //启动 ScriptIntrinsicBlur, + script.forEach(output) + + // Copy the output to the blurred bitmap + //将输出复制到模糊的位图 + output.copyTo(blurredBitmap) + + return blurredBitmap + } + + override fun updateDiskCacheKey(messageDigest: MessageDigest) { + messageDigest.update("blur transformation".toByteArray()) + } +} diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt index 0172fea6e..40c9cf32b 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt @@ -17,7 +17,7 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo override fun onActivityCreated(savedInstanceState: Bundle?) { viewModel.bookData.observe(this, Observer { showBook(it) }) - viewModel.loadData(intent) + viewModel.loadBook(intent) } private fun showBook(book: Book) { diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt index eafdc8b70..199f5f1a4 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt @@ -12,7 +12,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { val bookData = MutableLiveData() var inBookshelf = false - fun loadData(intent: Intent) { + fun loadBook(intent: Intent) { execute { intent.getStringExtra("bookUrl")?.let { App.db.bookDao().getBook(it)?.let { book -> diff --git a/app/src/main/res/layout/activity_book_info.xml b/app/src/main/res/layout/activity_book_info.xml index c93413b91..cf1e0fd1f 100644 --- a/app/src/main/res/layout/activity_book_info.xml +++ b/app/src/main/res/layout/activity_book_info.xml @@ -38,7 +38,8 @@ android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" - android:singleLine="true" /> + android:singleLine="true" + android:textSize="16sp" />