Switch of AntiAlias

This commit is contained in:
ag2s20150909 2022-05-08 12:08:20 +08:00
parent a6bf5d696c
commit b219391470
14 changed files with 47 additions and 8 deletions

View File

@ -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')

View File

@ -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"

View File

@ -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)

View File

@ -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()
}
}

View File

@ -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) {

View File

@ -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)
}

View File

@ -866,6 +866,8 @@
<string name="background_image_hint">Disabled when 0, enable range from 1 to 25\nThe greater the radius, the stronger the effect of blurring</string>
<string name="need_login">需登录</string>
<string name="pref_cronet_summary">使用Cronet网络组件</string>
<string name="anti_alias">Anti-Aliasing</string>
<string name="pref_anti_alias_summary">Anti-Aliasing when draw picture</string>
<string name="upload_url">上传URL</string>
<string name="download_url_rule">下载URL规则</string>
<string name="sort_by_respondTime">Ordenar por tiempo de respuesta</string>

View File

@ -869,6 +869,8 @@
<string name="background_image_hint">Disabled when 0, enable range from 1 to 25\nThe greater the radius, the stronger the effect of blurring</string>
<string name="need_login">需登录</string>
<string name="pref_cronet_summary">使用Cronet网络组件</string>
<string name="anti_alias">Anti-Aliasing</string>
<string name="pref_anti_alias_summary">Anti-Aliasing when draw picture</string>
<string name="upload_url">上传URL</string>
<string name="download_url_rule">下载URL规则</string>
<string name="sort_by_respondTime">Sort by respond time</string>

View File

@ -867,6 +867,8 @@
<string name="background_image_hint">Desativado quando 0, Ativado entre 1 e 25\n Quanto maior o raio, mais forte o efeito de desfocagem</string>
<string name="need_login">Login necessário</string>
<string name="pref_cronet_summary">Usando componentes de rede Cronet</string>
<string name="anti_alias">Anti-Aliasing</string>
<string name="pref_anti_alias_summary">Anti-Aliasing when draw picture</string>
<string name="upload_url">上传URL</string>
<string name="download_url_rule">下载URL规则</string>
<string name="sort_by_respondTime">Classificar por tempo de resposta</string>

View File

@ -866,6 +866,8 @@
<string name="check_source_show_debug_message_summary">書源校驗時顯示網絡請求步驟和時間</string>
<string name="need_login">需登錄</string>
<string name="pref_cronet_summary">使用Cronet網絡組件</string>
<string name="anti_alias">抗鋸齒</string>
<string name="pref_anti_alias_summary">繪製圖片時抗鋸齒</string>
<string name="upload_url">上傳URL</string>
<string name="download_url_rule">下載URL規則</string>
<string name="sort_by_respondTime">響應時間排序</string>

View File

@ -868,6 +868,8 @@
<string name="check_source_show_debug_message_summary">書源校驗時顯示網路請求步驟和時間</string>
<string name="need_login">需登入</string>
<string name="pref_cronet_summary">使用Cronet網路元件</string>
<string name="anti_alias">抗鋸齒</string>
<string name="pref_anti_alias_summary">繪製圖片時抗鋸齒</string>
<string name="upload_url">上傳URL</string>
<string name="download_url_rule">下載URL規則</string>
<string name="sort_by_respondTime">反應時間排序</string>

View File

@ -870,6 +870,8 @@
<string name="check_source_show_debug_message_summary">书源校验时显示网络请求步骤和时间</string>
<string name="need_login">需登录</string>
<string name="pref_cronet_summary">使用Cronet网络组件</string>
<string name="anti_alias">抗锯齿</string>
<string name="pref_anti_alias_summary">绘制图片时抗锯齿</string>
<string name="upload_url">上传URL</string>
<string name="download_url_rule">下载URL规则</string>
<string name="sort_by_respondTime">响应时间排序</string>

View File

@ -870,6 +870,8 @@
<string name="check_source_show_debug_message_summary">Show network status and timestamp during source checking</string>
<string name="need_login">need login</string>
<string name="pref_cronet_summary">use Cronet access network</string>
<string name="anti_alias">Anti-Aliasing</string>
<string name="pref_anti_alias_summary">Anti-Aliasing when draw picture</string>
<string name="upload_url">upload url</string>
<string name="download_url_rule">下载URL规则</string>
<string name="export_success">export success</string>
@ -974,5 +976,7 @@
<string name="soure_change_source">是否确认换源</string>
<string name="input_verification_code">输入验证码</string>
<string name="verification_code">验证码</string>
<!-- string end -->
</resources>

View File

@ -75,6 +75,11 @@
android:key="Cronet"
android:summary="@string/pref_cronet_summary"
android:title="Cronet" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false"
android:key="antiAlias"
android:summary="@string/pref_anti_alias_summary"
android:title="@string/anti_alias" />
<io.legado.app.ui.widget.prefs.Preference
android:key="preDownloadNum"