mirror of
https://github.com/gedoor/legado.git
synced 2025-01-08 11:47:32 +08:00
优化
This commit is contained in:
parent
d61d30c77e
commit
275e492c9f
@ -160,7 +160,7 @@ dependencies {
|
||||
//androidX
|
||||
implementation('androidx.core:core-ktx:1.12.0')
|
||||
implementation('androidx.appcompat:appcompat:1.6.1')
|
||||
implementation('androidx.activity:activity-ktx:1.7.2')
|
||||
implementation('androidx.activity:activity-ktx:1.8.0')
|
||||
implementation('androidx.fragment:fragment-ktx:1.6.1')
|
||||
implementation('androidx.preference:preference-ktx:1.2.1')
|
||||
implementation('androidx.constraintlayout:constraintlayout:2.1.4')
|
||||
@ -169,7 +169,7 @@ dependencies {
|
||||
implementation('androidx.webkit:webkit:1.8.0')
|
||||
|
||||
//google
|
||||
implementation('com.google.android.material:material:1.9.0')
|
||||
implementation('com.google.android.material:material:1.10.0')
|
||||
implementation('com.google.android.flexbox:flexbox:3.0.0')
|
||||
implementation('com.google.code.gson:gson:2.10.1')
|
||||
|
||||
@ -234,7 +234,7 @@ dependencies {
|
||||
|
||||
//二维码
|
||||
//noinspection GradleDependency
|
||||
implementation('com.github.jenly1314:zxing-lite:2.4.0')
|
||||
implementation('com.github.jenly1314:zxing-lite:3.0.1')
|
||||
|
||||
//颜色选择
|
||||
implementation('com.jaredrummler:colorpicker:1.1.0')
|
||||
|
@ -6,7 +6,6 @@ import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.google.zxing.Result
|
||||
import com.king.zxing.CameraScan.OnScanResultCallback
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.BaseActivity
|
||||
import io.legado.app.databinding.ActivityQrcodeCaptureBinding
|
||||
@ -16,7 +15,7 @@ import io.legado.app.utils.launch
|
||||
import io.legado.app.utils.readBytes
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
|
||||
class QrCodeActivity : BaseActivity<ActivityQrcodeCaptureBinding>(), OnScanResultCallback {
|
||||
class QrCodeActivity : BaseActivity<ActivityQrcodeCaptureBinding>(), ScanResultCallback {
|
||||
|
||||
override val binding by viewBinding(ActivityQrcodeCaptureBinding::inflate)
|
||||
|
||||
@ -47,12 +46,11 @@ class QrCodeActivity : BaseActivity<ActivityQrcodeCaptureBinding>(), OnScanResul
|
||||
return super.onCompatOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
override fun onScanResultCallback(result: Result?): Boolean {
|
||||
override fun onScanResultCallback(result: Result?) {
|
||||
val intent = Intent()
|
||||
intent.putExtra("result", result?.text)
|
||||
setResult(RESULT_OK, intent)
|
||||
finish()
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +1,19 @@
|
||||
package io.legado.app.ui.qrcode
|
||||
|
||||
import com.google.zxing.Result
|
||||
import com.king.zxing.CaptureFragment
|
||||
import com.king.camera.scan.AnalyzeResult
|
||||
import com.king.camera.scan.CameraScan
|
||||
import com.king.camera.scan.analyze.Analyzer
|
||||
import com.king.zxing.BarcodeCameraScanFragment
|
||||
import com.king.zxing.DecodeConfig
|
||||
import com.king.zxing.DecodeFormatManager
|
||||
import com.king.zxing.analyze.MultiFormatAnalyzer
|
||||
import com.king.zxing.analyze.QRCodeAnalyzer
|
||||
|
||||
class QrCodeFragment : BarcodeCameraScanFragment() {
|
||||
|
||||
class QrCodeFragment : CaptureFragment() {
|
||||
|
||||
override fun initCameraScan() {
|
||||
super.initCameraScan()
|
||||
override fun initCameraScan(cameraScan: CameraScan<Result>) {
|
||||
super.initCameraScan(cameraScan)
|
||||
//初始化解码配置
|
||||
val decodeConfig = DecodeConfig()
|
||||
//如果只有识别二维码的需求,这样设置效率会更高,不设置默认为DecodeFormatManager.DEFAULT_HINTS
|
||||
@ -24,9 +27,22 @@ class QrCodeFragment : CaptureFragment() {
|
||||
cameraScan.setAnalyzer(MultiFormatAnalyzer(decodeConfig))
|
||||
}
|
||||
|
||||
override fun onScanResultCallback(result: Result?): Boolean {
|
||||
(activity as? QrCodeActivity)?.onScanResultCallback(result)
|
||||
return true
|
||||
override fun createAnalyzer(): Analyzer<Result> {
|
||||
// 初始化解码配置
|
||||
val decodeConfig = DecodeConfig()
|
||||
decodeConfig.setHints(DecodeFormatManager.QR_CODE_HINTS) //如果只有识别二维码的需求,这样设置效率会更高,不设置默认为DecodeFormatManager.DEFAULT_HINTS
|
||||
.setFullAreaScan(false) //设置是否全区域识别,默认false
|
||||
.setAreaRectRatio(0.8f) //设置识别区域比例,默认0.8,设置的比例最终会在预览区域裁剪基于此比例的一个矩形进行扫码识别
|
||||
.setAreaRectVerticalOffset(0).areaRectHorizontalOffset =
|
||||
0 //设置识别区域水平方向偏移量,默认为0,为0表示居中,可以为负数
|
||||
|
||||
// BarcodeCameraScanActivity默认使用的MultiFormatAnalyzer,这里可以改为使用QRCodeAnalyzer
|
||||
return QRCodeAnalyzer(decodeConfig)
|
||||
}
|
||||
|
||||
override fun onScanResultCallback(result: AnalyzeResult<Result>) {
|
||||
cameraScan.setAnalyzeImage(false)
|
||||
(activity as? QrCodeActivity)?.onScanResultCallback(result.result)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package io.legado.app.ui.qrcode
|
||||
|
||||
import com.google.zxing.Result
|
||||
|
||||
interface ScanResultCallback {
|
||||
|
||||
fun onScanResultCallback(result: Result?)
|
||||
|
||||
}
|
@ -24,7 +24,6 @@ import com.google.zxing.common.HybridBinarizer
|
||||
import com.google.zxing.qrcode.QRCodeWriter
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
|
||||
import com.king.zxing.DecodeFormatManager
|
||||
import com.king.zxing.util.LogUtils
|
||||
import java.util.EnumMap
|
||||
import kotlin.math.max
|
||||
|
||||
@ -103,7 +102,7 @@ object QRCodeUtils {
|
||||
}
|
||||
return bitmap
|
||||
} catch (e: WriterException) {
|
||||
LogUtils.w(e.message)
|
||||
e.printOnDebug()
|
||||
}
|
||||
return null
|
||||
}
|
||||
@ -161,7 +160,7 @@ object QRCodeUtils {
|
||||
canvas.restore()
|
||||
} catch (e: Exception) {
|
||||
bitmap = null
|
||||
LogUtils.w(e.message)
|
||||
e.printOnDebug()
|
||||
}
|
||||
return bitmap
|
||||
}
|
||||
@ -222,7 +221,7 @@ object QRCodeUtils {
|
||||
}
|
||||
}
|
||||
} catch (e: java.lang.Exception) {
|
||||
LogUtils.w(e.message)
|
||||
e.printOnDebug()
|
||||
} finally {
|
||||
reader.reset()
|
||||
}
|
||||
@ -295,7 +294,7 @@ object QRCodeUtils {
|
||||
result = decodeInternal(reader, source.rotateCounterClockwise())
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
LogUtils.w(e.message)
|
||||
e.printOnDebug()
|
||||
} finally {
|
||||
reader.reset()
|
||||
}
|
||||
@ -416,7 +415,7 @@ object QRCodeUtils {
|
||||
addCode(bitmap, content, textSize, codeColor, textSize / 2)
|
||||
} else bitmap
|
||||
} catch (e: WriterException) {
|
||||
LogUtils.w(e.message)
|
||||
e.printOnDebug()
|
||||
}
|
||||
return null
|
||||
}
|
||||
@ -471,7 +470,7 @@ object QRCodeUtils {
|
||||
canvas.restore()
|
||||
} catch (e: Exception) {
|
||||
bitmap = null
|
||||
LogUtils.w(e.message)
|
||||
e.printOnDebug()
|
||||
}
|
||||
return bitmap
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ buildscript {
|
||||
build_tool_version = '34.0.0'
|
||||
kotlin_version = '1.9.10'
|
||||
ksp_version = "1.0.13"
|
||||
agp_version = '8.1.1'
|
||||
agp_version = '8.1.2'
|
||||
media3_version = "1.1.1"
|
||||
splitties_version = '3.0.0'
|
||||
room_version = '2.5.2'
|
||||
|
@ -30,5 +30,5 @@ android {
|
||||
|
||||
dependencies {
|
||||
compileOnly "com.android.tools.build:gradle:$agp_version"
|
||||
implementation "androidx.annotation:annotation:1.6.0"
|
||||
implementation 'androidx.annotation:annotation:1.7.0'
|
||||
}
|
Loading…
Reference in New Issue
Block a user