Skip to content

Commit

Permalink
更新CameraX至v1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jenly1314 committed Apr 15, 2023
1 parent 4bf19da commit 0279619
Show file tree
Hide file tree
Showing 50 changed files with 501 additions and 353 deletions.
105 changes: 56 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,43 +94,44 @@ Camera:为各个子库提供相机预览分析的核心库
## ViewfinderView相关字段说明

| 属性 | 属性类型 | 默认值 | 属性说明 |
| :------| :------ | :------ | :------ |
| maskColor | color |<font color=#000000>#60000000</font>| 扫描区外遮罩的颜色 |
| frameColor | color |<font color=#1FB3E2>#7F1FB3E2</font>| 扫描区边框的颜色 |
| cornerColor | color |<font color=#1FB3E2>#FF1FB3E2</font>| 扫描区边角的颜色 |
| laserColor | color |<font color=#1FB3E2>#FF1FB3E2</font>| 扫描区激光线的颜色 |
| labelText | string | | 扫描提示文本信息 |
| labelTextColor | color |<font color=#C0C0C0>#FFC0C0C0</font>| 提示文本字体颜色 |
| labelTextSize | dimension |14sp| 提示文本字体大小 |
| labelTextPadding | dimension |24dp| 提示文本距离扫描区的间距 |
| labelTextWidth | dimension | | 提示文本的宽度,默认为View的宽度 |
| labelTextLocation | enum |bottom| 提示文本显示位置 |
| frameWidth | dimension | | 扫码框宽度 |
| frameHeight | dimension | | 扫码框高度 |
| laserStyle | enum | line | 扫描激光的样式 |
| gridColumn | integer | 20 | 网格扫描激光列数 |
| gridHeight | integer | 40dp | 网格扫描激光高度,为0dp时,表示动态铺满 |
| cornerRectWidth | dimension | 4dp | 扫描区边角的宽 |
| cornerRectHeight | dimension | 16dp | 扫描区边角的高 |
| 属性 | 属性类型 | 默认值 | 属性说明 |
|:------------------------| :------ | :------ | :------ |
| maskColor | color |<font color=#000000>#60000000</font>| 扫描区外遮罩的颜色 |
| frameColor | color |<font color=#1FB3E2>#7F1FB3E2</font>| 扫描区边框的颜色 |
| cornerColor | color |<font color=#1FB3E2>#FF1FB3E2</font>| 扫描区边角的颜色 |
| laserColor | color |<font color=#1FB3E2>#FF1FB3E2</font>| 扫描区激光线的颜色 |
| labelText | string | | 扫描提示文本信息 |
| labelTextColor | color |<font color=#C0C0C0>#FFC0C0C0</font>| 提示文本字体颜色 |
| labelTextSize | dimension |14sp| 提示文本字体大小 |
| labelTextPadding | dimension |24dp| 提示文本距离扫描区的间距 |
| labelTextWidth | dimension | | 提示文本的宽度,默认为View的宽度 |
| labelTextLocation | enum |bottom| 提示文本显示位置 |
| frameWidth | dimension | | 扫码框宽度 |
| frameHeight | dimension | | 扫码框高度 |
| laserStyle | enum | line | 扫描激光的样式 |
| gridColumn | integer | 20 | 网格扫描激光列数 |
| gridHeight | integer | 40dp | 网格扫描激光高度,为0dp时,表示动态铺满 |
| cornerRectWidth | dimension | 4dp | 扫描区边角的宽 |
| cornerRectHeight | dimension | 16dp | 扫描区边角的高 |
| scannerLineMoveDistance | dimension | 2dp | 扫描线每次移动距离 |
| scannerLineHeight | dimension | 5dp | 扫描线高度 |
| frameLineWidth | dimension | 1dp | 边框线宽度 |
| scannerAnimationDelay | integer | 20 | 扫描动画延迟间隔时间,单位:毫秒 |
| frameRatio | float | 0.625f | 扫码框与屏幕占比 |
| framePaddingLeft | dimension | 0 | 扫码框左边的内间距 |
| framePaddingTop | dimension | 0 | 扫码框上边的内间距 |
| framePaddingRight | dimension | 0 | 扫码框右边的内间距 |
| framePaddingBottom | dimension | 0 | 扫码框下边的内间距 |
| frameGravity | enum | center | 扫码框对齐方式 |
| pointColor | color | <font color=#1FB3E2>#FF1FB3E2</font> | 结果点的颜色 |
| pointStrokeColor | color | <font color=#FFFFFF>#FFFFFFFF</font> | 结果点描边的颜色 |
| pointRadius | dimension | 15dp | 结果点的半径 |
| pointStrokeRatio | float | 1.2 | 结果点描边半径与结果点半径的比例 |
| pointDrawable | reference | | 结果点自定义图片 |
| showPointAnim | boolean | true | 是否显示结果点的动画 |
| laserDrawable | reference | | 扫描激光自定义图片 |
| viewfinderStyle | enum | classic | 取景框样式;支持:classic:经典样式(带扫码框那种)、popular:流行样式(不带扫码框) |
| scannerLineHeight | dimension | 5dp | 扫描线高度 |
| frameLineWidth | dimension | 1dp | 边框线宽度 |
| scannerAnimationDelay | integer | 20 | 扫描动画延迟间隔时间,单位:毫秒 |
| frameRatio | float | 0.625f | 扫码框与屏幕占比 |
| framePaddingLeft | dimension | 0 | 扫码框左边的内间距 |
| framePaddingTop | dimension | 0 | 扫码框上边的内间距 |
| framePaddingRight | dimension | 0 | 扫码框右边的内间距 |
| framePaddingBottom | dimension | 0 | 扫码框下边的内间距 |
| frameGravity | enum | center | 扫码框对齐方式 |
| pointColor | color | <font color=#1FB3E2>#FF1FB3E2</font> | 结果点的颜色 |
| pointStrokeColor | color | <font color=#FFFFFF>#FFFFFFFF</font> | 结果点描边的颜色 |
| pointRadius | dimension | 15dp | 结果点的半径 |
| pointStrokeRatio | float | 1.2 | 结果点描边半径与结果点半径的比例 |
| pointDrawable | reference | | 结果点自定义图片 |
| showPointAnim | boolean | true | 是否显示结果点的动画 |
| laserDrawable | reference | | 扫描激光自定义图片 |
| laserDrawableRatio | float | 0.625f | 激光扫描图片与屏幕占比 |
| viewfinderStyle | enum | classic | 取景框样式;支持:classic:经典样式(带扫码框那种)、popular:流行样式(不带扫码框) |

## 引入

Expand All @@ -152,39 +153,39 @@ allprojects {
```gradle
//Camera核心 (*必须)
implementation 'com.github.jenly1314.MLKit:mlkit-camera-core:1.3.0'
implementation 'com.github.jenly1314.MLKit:mlkit-camera-core:1.4.0'
//--------------------------
//公共库 (可选) (1.3.0新增:当使用到MLKit下面的子库时,需依赖公共库)
implementation 'com.github.jenly1314.MLKit:mlkit-common:1.3.0'
implementation 'com.github.jenly1314.MLKit:mlkit-common:1.4.0'
//条码识别 (可选)
implementation 'com.github.jenly1314.MLKit:mlkit-barcode-scanning:1.3.0'
implementation 'com.github.jenly1314.MLKit:mlkit-barcode-scanning:1.4.0'
//人脸检测 (可选)
implementation 'com.github.jenly1314.MLKit:mlkit-face-detection:1.3.0'
implementation 'com.github.jenly1314.MLKit:mlkit-face-detection:1.4.0'
//人脸网格检测 (可选)
implementation 'com.github.jenly1314.MLKit:mlkit-face-mesh-detection:1.3.0'
implementation 'com.github.jenly1314.MLKit:mlkit-face-mesh-detection:1.4.0'
//图像标签 (可选)
implementation 'com.github.jenly1314.MLKit:mlkit-image-labeling:1.3.0'
implementation 'com.github.jenly1314.MLKit:mlkit-image-labeling:1.4.0'
//对象检测 (可选)
implementation 'com.github.jenly1314.MLKit:mlkit-object-detection:1.3.0'
implementation 'com.github.jenly1314.MLKit:mlkit-object-detection:1.4.0'
//姿势检测 (可选)
implementation 'com.github.jenly1314.MLKit:mlkit-pose-detection:1.3.0'
implementation 'com.github.jenly1314.MLKit:mlkit-pose-detection:1.4.0'
//姿势检测精确版 (可选)
implementation 'com.github.jenly1314.MLKit:mlkit-pose-detection-accurate:1.3.0'
implementation 'com.github.jenly1314.MLKit:mlkit-pose-detection-accurate:1.4.0'
//自拍分割 (可选)
implementation 'com.github.jenly1314.MLKit:mlkit-segmentation-selfie:1.3.0'
implementation 'com.github.jenly1314.MLKit:mlkit-segmentation-selfie:1.4.0'
//文字识别 (可选)
implementation 'com.github.jenly1314.MLKit:mlkit-text-recognition:1.3.0'
implementation 'com.github.jenly1314.MLKit:mlkit-text-recognition:1.4.0'
```

Expand All @@ -205,7 +206,7 @@ implementation 'com.github.jenly1314.MLKit:mlkit-text-recognition:1.3.0'
> 1、通过继承 **BaseCameraScanActivity** 或者 **BaseCameraScanFragment** 或其子类,可快速实现扫描识别。
> (适用于大多场景,自定义布局时需覆写 **getLayoutId** 方法)
> 2、在你项目的Activity或者Fragment中实例化一个 **BaseCameraScan**。(适用于想在扫码界面写交互逻辑,又因为项目
> 2、在你项目的Activity或者Fragment中实例化一个 **BaseCameraScan**。(适用于想在扫描界面写交互逻辑,又因为项目
> 架构或其它原因,无法直接或间接继承 **BaseCameraScanActivity****BaseCameraScanFragment** 时使用)
> 3、继承 **CameraScan** 自己实现一个,可参照默认实现类 **BaseCameraScan**,其他步骤同方式2。(高级用法,谨慎使用)
Expand Down Expand Up @@ -263,7 +264,7 @@ implementation 'com.github.jenly1314.MLKit:mlkit-text-recognition:1.3.0'
// 获取CameraScan,根据需要修改相关配置
getCameraScan().setPlayBeep(true)//设置是否播放音效,默认为false
.setVibrate(true)//设置是否震动,默认为false
.setCameraConfig(new CameraConfig())//设置相机配置信息,CameraConfig可覆写options方法自定义配置
.setCameraConfig(new ResolutionCameraConfig(this))//设置相机配置信息,CameraConfig可覆写options方法自定义配置
.setNeedTouchZoom(true)//支持多指触摸捏合缩放,默认为true
.setDarkLightLux(45f)//设置光线足够暗的阈值(单位:lux),需要通过{@link #bindFlashlightView(View)}绑定手电筒才有效
.setBrightLightLux(100f)//设置光线足够明亮的阈值(单位:lux),需要通过{@link #bindFlashlightView(View)}绑定手电筒才有效
Expand Down Expand Up @@ -468,6 +469,12 @@ compileOptions {

## 版本记录

#### v1.4.0:2023-4-15
* 优化CameraScan的缺省配置(CameraConfig相关配置)
* 优化ViewfinderView自定义属性(新增laserDrawableRatio)
* 更新MLKit相关依赖库版本
* 更新CameraX至v1.2.2

#### v1.3.0:2023-2-23
* 新增公共库(mlkit-common)
* 优化注释
Expand Down
8 changes: 3 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
}

android {
namespace 'com.king.mlkit.vision.app'
compileSdk build_versions.compileSdk

defaultConfig {
Expand All @@ -27,25 +28,22 @@ android {
}
}


compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = '1.8'
jvmTarget = JavaVersion.VERSION_11.toString()
}
lint {
abortOnError false
}
namespace 'com.king.mlkit.vision.app'
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation deps.test.junit
androidTestImplementation deps.test.runner
androidTestImplementation deps.test.android_ext_junit
androidTestImplementation deps.test.espresso

implementation deps.androidx.material
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 7,
"versionName": "1.3.0",
"versionCode": 8,
"versionName": "1.4.0",
"outputFile": "app-release.apk"
}
],
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
android:theme="@style/CameraScanTheme"/>

<activity android:name=".barcode.QRCodeScanningActivity"
android:screenOrientation="portrait"

android:exported="false"
android:theme="@style/CameraScanTheme"/>

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/king/mlkit/vision/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class MainActivity : AppCompatActivity() {
Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
}

/**
* 处理图片 - 从图片中获取条码结果
*/
private fun processPhoto(data: Uri?) {
data?.let {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ import com.king.mlkit.vision.app.R
import com.king.mlkit.vision.app.drawRect
import com.king.mlkit.vision.barcode.BarcodeCameraScanActivity
import com.king.mlkit.vision.camera.AnalyzeResult
import com.king.mlkit.vision.camera.CameraScan
import com.king.mlkit.vision.camera.config.ResolutionCameraConfig

/**
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/
class BarcodeScanningActivity : BarcodeCameraScanActivity() {

override fun initCameraScan() {
super.initCameraScan()
override fun initCameraScan(cameraScan: CameraScan<MutableList<Barcode>>) {
super.initCameraScan(cameraScan)
cameraScan.setPlayBeep(true)
.setVibrate(true)
.setCameraConfig(ResolutionCameraConfig(this))//设置CameraConfig
// .setCameraConfig(ResolutionCameraConfig(this))// 设置CameraConfig
}

override fun onScanResultCallback(result: AnalyzeResult<MutableList<Barcode>>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@ 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 com.king.mlkit.vision.camera.config.AspectRatioCameraConfig
import com.king.mlkit.vision.camera.config.ResolutionCameraConfig
import com.king.mlkit.vision.camera.CameraScan

/**
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/
class MultipleQRCodeScanningActivity : QRCodeCameraScanActivity() {

override fun initCameraScan() {
super.initCameraScan()
override fun initCameraScan(cameraScan: CameraScan<MutableList<Barcode>>) {
super.initCameraScan(cameraScan)
cameraScan.setPlayBeep(true)
.setVibrate(true)
// .setCameraConfig(AspectRatioCameraConfig(this))
.setCameraConfig(ResolutionCameraConfig(this, ResolutionCameraConfig.IMAGE_QUALITY_720P))
// .setCameraConfig(ResolutionCameraConfig(this))
}

override fun getLayoutId(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.king.mlkit.vision.app.R
import com.king.mlkit.vision.barcode.QRCodeCameraScanActivity
import com.king.mlkit.vision.camera.AnalyzeResult
import com.king.mlkit.vision.camera.CameraScan
import com.king.mlkit.vision.camera.config.AspectRatioCameraConfig
import com.king.mlkit.vision.camera.util.PointUtils

/**
Expand All @@ -39,8 +38,8 @@ class QRCodeScanningActivity : QRCodeCameraScanActivity() {
ivResult = findViewById(R.id.ivResult)
}

override fun initCameraScan() {
super.initCameraScan()
override fun initCameraScan(cameraScan: CameraScan<MutableList<Barcode>>) {
super.initCameraScan(cameraScan)
cameraScan.setPlayBeep(true)
.setVibrate(true)
.bindFlashlightView(ivFlashlight)
Expand Down
Binary file added app/src/main/res/drawable-xhdpi/ic_laser_line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion app/src/main/res/layout/qrcode_scan_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:viewfinderStyle="popular"
app:frameRatio="0.9" />
app:laserStyle="image"
app:laserDrawableRatio="0.8"
app:laserDrawable="@drawable/ic_laser_line"/>
<ImageView
android:id="@+id/ivFlashlight"
android:layout_width="wrap_content"
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ buildscript {
apply from: 'versions.gradle'
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
// id 'org.jetbrains.dokka' version '1.7.0' apply false
id 'com.vanniktech.maven.publish' version '0.20.0' apply false
id 'com.vanniktech.maven.publish' version '0.22.0' apply false
}
6 changes: 6 additions & 0 deletions change_log.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## 版本记录

#### v1.4.0:2023-4-15
* 优化CameraScan的缺省配置(CameraConfig相关配置)
* 优化ViewfinderView自定义属性(新增laserDrawableRatio)
* 更新MLKit相关依赖库版本
* 更新CameraX至v1.2.2

#### v1.3.0:2023-2-23
* 新增公共库(mlkit-common)
* 优化注释
Expand Down
5 changes: 2 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android.enableJetifier = true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style = official

VERSION_NAME=1.3.0
VERSION_CODE=7
VERSION_NAME=1.4.0
VERSION_CODE=8
GROUP=com.github.jenly1314.MLKit

POM_DESCRIPTION=MLKit for Android
Expand All @@ -31,7 +31,6 @@ POM_SCM_URL=https://github.com/jenly1314/MLKit
POM_SCM_CONNECTION=scm:git@github.com:jenly1314/MLKit.git
POM_SCM_DEV_CONNECTION=scm:git@github.com:jenly1314/MLKit.git


#POM_LICENCE_NAME=The MIT License
#POM_LICENCE_URL=https://opensource.org/licenses/mit-license.php
POM_LICENCE_NAME=The Apache Software License, Version 2.0
Expand Down
14 changes: 4 additions & 10 deletions mlkit-barcode-scanning/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
}

android {
namespace 'com.king.mlkit.vision.barcode'
compileSdk build_versions.compileSdk

defaultConfig {
Expand All @@ -20,29 +21,22 @@ android {
}
}


compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
lint {
abortOnError false
}
namespace 'com.king.mlkit.vision.barcode'
}

//task javadoc(type: Javadoc) {
// source = android.sourceSets.main.java.srcDirs
// classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
//}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation deps.test.junit
androidTestImplementation deps.test.runner
androidTestImplementation deps.test.android_ext_junit
androidTestImplementation deps.test.espresso

compileOnly deps.androidx.appcompat
compileOnly deps.androidx.appcompat
api deps.google_mlkit_barcode_scanning

compileOnly project(':mlkit-camera-core')
Expand Down
Loading

0 comments on commit 0279619

Please sign in to comment.