From b219391470a2af4a8914d97703715c79b755baf4 Mon Sep 17 00:00:00 2001 From: ag2s20150909 Date: Sun, 8 May 2022 12:08:20 +0800 Subject: [PATCH] Switch of AntiAlias --- app/build.gradle | 2 +- .../main/java/io/legado/app/constant/PreferKey.kt | 2 ++ .../java/io/legado/app/help/config/AppConfig.kt | 3 ++- .../io/legado/app/help/http/cronet/AbsCallBack.kt | 6 +++++- .../app/help/http/cronet/CronetInterceptor.kt | 6 +++++- .../app/ui/book/read/page/ContentTextView.kt | 15 +++++++++++---- app/src/main/res/values-es-rES/strings.xml | 2 ++ app/src/main/res/values-ja-rJP/strings.xml | 2 ++ app/src/main/res/values-pt-rBR/strings.xml | 2 ++ app/src/main/res/values-zh-rHK/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ app/src/main/res/values-zh/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 4 ++++ app/src/main/res/xml/pref_config_other.xml | 5 +++++ 14 files changed, 47 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8cbce29c4..d380dbb4d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -157,7 +157,7 @@ dependencies { implementation('androidx.webkit:webkit:1.4.0') //google - implementation('com.google.android.material:material:1.5.0') + implementation('com.google.android.material:material:1.6.0') implementation('com.google.android.flexbox:flexbox:3.0.0') implementation('com.google.code.gson:gson:2.9.0') diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index bf53e23a8..588ca8581 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -80,6 +80,8 @@ object PreferKey { const val importKeepName = "importKeepName" const val screenOrientation = "screenOrientation" const val syncBookProgress = "syncBookProgress" + const val cronet = "Cronet" + const val antiAlias = "antiAlias" const val preDownloadNum = "preDownloadNum" const val autoRefresh = "auto_refresh" const val defaultToRead = "defaultToRead" diff --git a/app/src/main/java/io/legado/app/help/config/AppConfig.kt b/app/src/main/java/io/legado/app/help/config/AppConfig.kt index c0bf7709e..f36decf1d 100644 --- a/app/src/main/java/io/legado/app/help/config/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/AppConfig.kt @@ -11,7 +11,8 @@ import splitties.init.appCtx @Suppress("MemberVisibilityCanBePrivate") object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { val isGooglePlay = appCtx.channel == "google" - val isCronet = appCtx.getPrefBoolean("Cronet") + val isCronet = appCtx.getPrefBoolean(PreferKey.cronet) + val useAntiAlias = appCtx.getPrefBoolean(PreferKey.antiAlias) var userAgent: String = getPrefUserAgent() var isEInkMode = appCtx.getPrefString(PreferKey.themeMode) == "3" var clickActionTL = appCtx.getPrefInt(PreferKey.clickActionTL, 2) diff --git a/app/src/main/java/io/legado/app/help/http/cronet/AbsCallBack.kt b/app/src/main/java/io/legado/app/help/http/cronet/AbsCallBack.kt index 0728b1db3..192206435 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/AbsCallBack.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/AbsCallBack.kt @@ -21,7 +21,7 @@ abstract class AbsCallBack( private val eventListener: EventListener? = null, private val responseCallback: Callback? = null -) : UrlRequest.Callback() { +) : UrlRequest.Callback(), AutoCloseable { val buffer = Buffer() @@ -225,4 +225,8 @@ abstract class AbsCallBack( .build() } } + + override fun close() { + buffer.clear() + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt index ffd701268..daa774dfa 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt @@ -4,11 +4,15 @@ import android.os.Build import io.legado.app.utils.printOnDebug import okhttp3.* import okhttp3.internal.http.receiveHeaders +import java.io.IOException class CronetInterceptor(private val cookieJar: CookieJar = CookieJar.NO_COOKIES) : Interceptor { - + @Throws(IOException::class) override fun intercept(chain: Interceptor.Chain): Response { + if (chain.call().isCanceled()) { + throw IOException("Canceled") + } val original: Request = chain.request() //Cronet未初始化 return if (!CronetLoader.install() || cronetEngine == null) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index d6e498e12..a9fdb979a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -3,13 +3,13 @@ package io.legado.app.ui.book.read.page import android.content.Context import android.graphics.Canvas import android.graphics.Paint -import android.graphics.PaintFlagsDrawFilter import android.graphics.RectF import android.util.AttributeSet import android.view.View import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Bookmark +import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.lib.theme.accentColor import io.legado.app.model.ReadBook @@ -49,12 +49,20 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at private val pageFactory: TextPageFactory get() = callBack.pageFactory private var pageOffset = 0 + //绘制图片的paint + private val imagePaint by lazy { + Paint().apply { + isAntiAlias = AppConfig.useAntiAlias + } + } + init { callBack = activity as CallBack } fun setContent(textPage: TextPage) { this.textPage = textPage + imagePaint.isAntiAlias = AppConfig.useAntiAlias invalidate() } @@ -163,8 +171,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at lineTop: Float, lineBottom: Float ) { - canvas.drawFilter = - PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG) + val book = ReadBook.book ?: return val bitmap = ImageProvider.getImage( book, @@ -181,7 +188,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at RectF(textChar.start, lineTop + div, textChar.end, lineBottom - div) } kotlin.runCatching { - canvas.drawBitmap(bitmap, null, rectF, null) + canvas.drawBitmap(bitmap, null, rectF, imagePaint) }.onFailure { e -> context.toastOnUi(e.localizedMessage) } diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index f62a1d248..c9f72740e 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -866,6 +866,8 @@ Disabled when 0, enable range from 1 to 25\nThe greater the radius, the stronger the effect of blurring 需登录 使用Cronet网络组件 + Anti-Aliasing + Anti-Aliasing when draw picture 上传URL 下载URL规则 Ordenar por tiempo de respuesta diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 11a2729de..7f71a4052 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -869,6 +869,8 @@ Disabled when 0, enable range from 1 to 25\nThe greater the radius, the stronger the effect of blurring 需登录 使用Cronet网络组件 + Anti-Aliasing + Anti-Aliasing when draw picture 上传URL 下载URL规则 Sort by respond time diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index f0e4b8cf3..2557fcd28 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -867,6 +867,8 @@ Desativado quando 0, Ativado entre 1 e 25\n Quanto maior o raio, mais forte o efeito de desfocagem Login necessário Usando componentes de rede Cronet + Anti-Aliasing + Anti-Aliasing when draw picture 上传URL 下载URL规则 Classificar por tempo de resposta diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 7b938e9f3..d5eb8d2fe 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -866,6 +866,8 @@ 書源校驗時顯示網絡請求步驟和時間 需登錄 使用Cronet網絡組件 + 抗鋸齒 + 繪製圖片時抗鋸齒 上傳URL 下載URL規則 響應時間排序 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 6ba87de41..34698cecd 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -868,6 +868,8 @@ 書源校驗時顯示網路請求步驟和時間 需登入 使用Cronet網路元件 + 抗鋸齒 + 繪製圖片時抗鋸齒 上傳URL 下載URL規則 反應時間排序 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 7b0f3ef18..a6b6d27a9 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -870,6 +870,8 @@ 书源校验时显示网络请求步骤和时间 需登录 使用Cronet网络组件 + 抗锯齿 + 绘制图片时抗锯齿 上传URL 下载URL规则 响应时间排序 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 05df4e53b..d8ec067af 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -870,6 +870,8 @@ Show network status and timestamp during source checking need login use Cronet access network + Anti-Aliasing + Anti-Aliasing when draw picture upload url 下载URL规则 export success @@ -974,5 +976,7 @@ 是否确认换源 输入验证码 验证码 + + diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 9388b4878..0b0d6ffa8 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -75,6 +75,11 @@ android:key="Cronet" android:summary="@string/pref_cronet_summary" android:title="Cronet" /> +