1 Star 0 Fork 107

醉步天下 / MLKit

forked from Jenly / MLKit 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
MultipleQRCodeScanningActivity.kt 2.31 KB
AI 代码解读
一键复制 编辑 原始数据 按行查看 历史
Jenly 提交于 2021-10-18 18:04 . 更新CameraX至v1.0.2
/*
* Copyright (C) Jenly, MLKit Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.king.mlkit.vision.app.barcode
import android.widget.ImageView
import com.google.mlkit.vision.barcode.Barcode
import com.king.app.dialog.AppDialog
import com.king.app.dialog.AppDialogConfig
import com.king.mlkit.vision.app.R
import com.king.mlkit.vision.app.drawRect
import com.king.mlkit.vision.barcode.QRCodeCameraScanActivity
import com.king.mlkit.vision.camera.AnalyzeResult
import java.lang.StringBuilder
/**
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/
class MultipleQRCodeScanningActivity : QRCodeCameraScanActivity() {
override fun initCameraScan() {
super.initCameraScan()
cameraScan.setPlayBeep(true)
.setVibrate(true)
}
override fun getLayoutId(): Int {
return R.layout.multiple_qrcode_scan_activity
}
override fun onScanResultCallback(result: AnalyzeResult<MutableList<Barcode>>) {
cameraScan.setAnalyzeImage(false)
val buffer = StringBuilder()
val bitmap = result.bitmap.drawRect {canvas,paint ->
for ((index,data) in result.result.withIndex()) {
buffer.append("[$index] ").append(data.displayValue).append("\n")
canvas.drawRect(data.boundingBox,paint)
}
}
val config = AppDialogConfig(this, R.layout.barcode_result_dialog)
config.setContent(buffer).setOnClickOk {
AppDialog.INSTANCE.dismissDialog()
cameraScan.setAnalyzeImage(true)
}.setOnClickCancel {
AppDialog.INSTANCE.dismissDialog()
finish()
}
val imageView = config.getView<ImageView>(R.id.ivDialogContent)
imageView.setImageBitmap(bitmap)
AppDialog.INSTANCE.showDialog(config,false)
}
}
Java
1
https://gitee.com/shhg/MLKit.git
git@gitee.com:shhg/MLKit.git
shhg
MLKit
MLKit
master

搜索帮助