更新CameraX至v1.1.0-rc01
This commit is contained in:
78
README.md
78
README.md
@@ -13,7 +13,7 @@
|
||||
[](https://jenly1314.github.io/)
|
||||
[](http://shang.qq.com/wpa/qunwpa?idkey=8fcc6a2f88552ea44b1.1.982c94fd124f7bb3ec227e2a400dbbfaad3dc2f5ad)
|
||||
|
||||
ZXingLite for Android 是ZXing的精简版,基于ZXing库优化扫码和生成二维码/条形码功能,扫码界面完全支持自定义,也可一行代码使用默认实现的扫码功能。总之你想要的都在这里。
|
||||
ZXingLite for Android 是ZXing的精简极速版,基于ZXing库优化扫码和生成二维码/条形码功能,扫码界面完全支持自定义,也可一行代码使用默认实现的扫码功能。总之你想要的都在这里。
|
||||
>简单如斯,你不试试? Come on~
|
||||
|
||||
|
||||
@@ -57,8 +57,6 @@ ZXingLite for Android 是ZXing的精简版,基于ZXing库优化扫码和生成
|
||||
|
||||
## 引入
|
||||
|
||||
> 由于2021年2月3日 **JFrog宣布将关闭Bintray和JCenter,计划在2022年2月完全关闭。** 所以后续版本不再发布至 **JCenter**
|
||||
|
||||
### Gradle:
|
||||
|
||||
1. 在Project的 **build.gradle** 里面添加远程仓库
|
||||
@@ -76,7 +74,7 @@ allprojects {
|
||||
|
||||
```gradle
|
||||
//AndroidX 版本
|
||||
implementation 'com.github.jenly1314:zxing-lite:2.1.1'
|
||||
implementation 'com.github.jenly1314:zxing-lite:2.2.0'
|
||||
|
||||
```
|
||||
|
||||
@@ -88,7 +86,7 @@ implementation 'com.king.zxing:zxing-lite:2.0.3'
|
||||
|
||||
```
|
||||
|
||||
**v1.x** 旧版本
|
||||
**v1.x** 旧版本 [v1.1.9](https://github.com/jenly1314/ZXingLite/tree/androidx)
|
||||
```gradle
|
||||
//AndroidX 版本
|
||||
implementation 'com.king.zxing:zxing-lite:1.1.9-androidx'
|
||||
@@ -97,35 +95,17 @@ implementation 'com.king.zxing:zxing-lite:1.1.9-androidx'
|
||||
implementation 'com.king.zxing:zxing-lite:1.1.9'
|
||||
```
|
||||
|
||||
## 版本说明
|
||||
|
||||
### v2.x 基于CameraX重构震撼发布
|
||||
### 快速实现扫码有以下几种方式:
|
||||
|
||||
#### v2.x 相对于 v1.x 的优势
|
||||
> 1、直接使用CaptureActivity或者CaptureFragment。(纯洁的扫码,无任何添加剂)
|
||||
|
||||
* v2.x基于CameraX,抽象整体流程,可扩展性更高。
|
||||
* v2.x基于CameraX通过预览裁剪的方式确保预览界面不变形,无需铺满屏幕,就能适配(v1.x通过遍历Camera支持预览的尺寸,找到与屏幕最接近的比例,减少变形的可能性(需铺满屏幕,才能适配))
|
||||
> 2、通过继承CaptureActivity或者CaptureFragment并自定义布局。(适用于大多场景,并无需关心扫码相关逻辑,自定义布局时需覆写getLayoutId方法)实现示例:[CustomCaptureActivity](app/src/main/java/com/king/zxing/app/CustomCaptureActivity.java) 和 [QRCodeActivity](app/src/main/java/com/king/zxing/app/QRCodeActivity.java)
|
||||
|
||||
#### v2.x 特别说明
|
||||
> 3、在你项目的Activity或者Fragment中实例化一个CameraScan即可。(适用于想在扫码界面写交互逻辑,又因为项目架构或其它原因,无法直接或间接继承CaptureActivity或CaptureFragment时使用)实现示例:[CustomActivity](app/src/main/java/com/king/zxing/app/CustomActivity.java)
|
||||
|
||||
* v2.x如果您是通过继承CaptureActivity或CaptureFragment实现扫码功能,那么动态权限申请相关都已经在CaptureActivity或CaptureFragment处理好了。
|
||||
* v2.x如果您是通过继承CaptureActivity或CaptureFragment实现扫码功能,如果有想要修改默认配置,可重写**initCameraScan**方法,修改CameraScan的配置即可,如果无需修改配置,直接在跳转原界面的**onActivityResult** 接收扫码结果即可(更多具体详情可参见[app](app)中的使用示例)。
|
||||
> 4、继承CameraScan自己实现一个,可参照默认实现类DefaultCameraScan,其它步骤同方式3。(扩展高级用法,谨慎使用)
|
||||
|
||||
##### 关于CameraX
|
||||
|
||||
* CameraX暂时还是Beta版,可能会存在一定的稳定性,如果您有这个考量,可以继续使用 **ZXingLite** 以前的 **v1.x** 版本。相信不久之后CameraX就会发布稳定版。
|
||||
|
||||
#### v1.x 说明
|
||||
|
||||
[【v1.1.9】](https://github.com/jenly1314/ZXingLite/tree/androidx) 如果您正在使用 **1.x** 版本请点击下面的链接查看分支版本,当前 **2.x** 版本已经基于 **CameraX** 进行重构,不支持升级,请在新项目中使用。
|
||||
|
||||
查看AndroidX版 **1.x** 分支 [请戳此处](https://github.com/jenly1314/ZXingLite/tree/androidx)
|
||||
|
||||
查看Android Support版 **1.x** 分支 [请戳此处](https://github.com/jenly1314/ZXingLite/tree/android)
|
||||
|
||||
查看 [ **1.x** API帮助文档](https://jenly1314.github.io/projects/ZXingLite/doc/)
|
||||
|
||||
使用 **v1.x** 版本的无需往下看了,下面的示例和相关说明都是针对于当前最新版本。
|
||||
|
||||
## 示例
|
||||
|
||||
@@ -286,15 +266,6 @@ public class QRCodeActivity extends CaptureActivity {
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
```
|
||||
|
||||
### 快速实现扫码有以下几种方式:
|
||||
|
||||
> 1、直接使用CaptureActivity或者CaptureFragment。(纯洁的扫码,无任何添加剂)
|
||||
|
||||
> 2、通过继承CaptureActivity或者CaptureFragment并自定义布局。(适用于大多场景,并无需关心扫码相关逻辑,自定义布局时需覆写getLayoutId方法)
|
||||
|
||||
> 3、在你项目的Activity或者Fragment中实例化一个CameraScan即可。(适用于想在扫码界面写交互逻辑,又因为项目架构或其它原因,无法直接或间接继承CaptureActivity或CaptureFragment时使用)
|
||||
|
||||
> 4、继承CameraScan自己实现一个,可参照默认实现类DefaultCameraScan,其它步骤同方式3。(扩展高级用法,谨慎使用)
|
||||
|
||||
### 其他
|
||||
|
||||
@@ -315,8 +286,41 @@ compileOptions {
|
||||
#### [MLKit](https://github.com/jenly1314/MLKit) 一个强大易用的工具包。通过ML Kit您可以很轻松的实现文字识别、条码识别、图像标记、人脸检测、对象检测等功能。
|
||||
#### [WeChatQRCode](https://github.com/jenly1314/WeChatQRCode) 基于OpenCV开源的微信二维码引擎移植的扫码识别库。
|
||||
|
||||
|
||||
## 版本说明
|
||||
|
||||
### v2.x 基于CameraX重构震撼发布
|
||||
|
||||
#### v2.x 相对于 v1.x 的优势
|
||||
|
||||
* v2.x基于CameraX,抽象整体流程,可扩展性更高。
|
||||
* v2.x基于CameraX通过预览裁剪的方式确保预览界面不变形,无需铺满屏幕,就能适配(v1.x通过遍历Camera支持预览的尺寸,找到与屏幕最接近的比例,减少变形的可能性(需铺满屏幕,才能适配))
|
||||
|
||||
#### v2.x 特别说明
|
||||
|
||||
* v2.x如果您是通过继承CaptureActivity或CaptureFragment实现扫码功能,那么动态权限申请相关都已经在CaptureActivity或CaptureFragment处理好了。
|
||||
* v2.x如果您是通过继承CaptureActivity或CaptureFragment实现扫码功能,如果有想要修改默认配置,可重写**initCameraScan**方法,修改CameraScan的配置即可,如果无需修改配置,直接在跳转原界面的**onActivityResult** 接收扫码结果即可(更多具体详情可参见[app](app)中的使用示例)。
|
||||
|
||||
##### 关于CameraX
|
||||
|
||||
* CameraX暂时还是Beta版,可能会存在一定的稳定性,如果您有这个考量,可以继续使用 **ZXingLite** 以前的 **v1.x** 版本。相信不久之后CameraX就会发布稳定版。
|
||||
|
||||
#### v1.x 说明
|
||||
|
||||
[【v1.1.9】](https://github.com/jenly1314/ZXingLite/tree/androidx) 如果您正在使用 **1.x** 版本请点击下面的链接查看分支版本,当前 **2.x** 版本已经基于 **CameraX** 进行重构,不支持升级,请在新项目中使用。
|
||||
|
||||
查看AndroidX版 **1.x** 分支 [请戳此处](https://github.com/jenly1314/ZXingLite/tree/androidx)
|
||||
|
||||
查看Android Support版 **1.x** 分支 [请戳此处](https://github.com/jenly1314/ZXingLite/tree/android)
|
||||
|
||||
查看 [ **1.x** API帮助文档](https://jenly1314.github.io/projects/ZXingLite/doc/)
|
||||
|
||||
## 版本记录
|
||||
|
||||
#### v2.2.0:2022-5-31
|
||||
* 更新CameraX至v1.1.0-rc01
|
||||
* 更新targetSdkVersion至31
|
||||
|
||||
#### v2.1.1:2021-8-4
|
||||
* 更新CameraX至v1.0.1
|
||||
* 优化CameraConfig的一些默认配置
|
||||
|
||||
Binary file not shown.
@@ -1 +0,0 @@
|
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":32,"versionName":"2.1.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release","dirName":""},"path":"app-release.apk","properties":{}}]
|
||||
@@ -2,7 +2,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.king.zxing.app">
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
@@ -16,7 +16,8 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity"
|
||||
android:screenOrientation="portrait">
|
||||
android:screenOrientation="portrait"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
|
||||
});
|
||||
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
10
build.gradle
10
build.gradle
@@ -24,7 +24,15 @@ allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
jcenter() // Warning: this repository is going to shut down soon
|
||||
// jcenter() // Warning: this repository is going to shut down soon
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
plugins.withId("com.vanniktech.maven.publish") {
|
||||
mavenPublish {
|
||||
sonatypeHost = "S01"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,22 +14,35 @@ org.gradle.jvmargs = -Xmx1536m
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
|
||||
VERSION_NAME=2.1.1
|
||||
VERSION_CODE=32
|
||||
VERSION_NAME=2.2.0
|
||||
VERSION_CODE=33
|
||||
GROUP=com.github.jenly1314
|
||||
|
||||
POM_DESCRIPTION=ZXingLite for Android
|
||||
POM_URL=https://github.com/jenly1314/ZXingLite
|
||||
|
||||
POM_SCM_URL=https://github.com/jenly1314/ZXingLite
|
||||
POM_SCM_CONNECTION=scm:git@github.com:jenly1314/ZXingLite.git
|
||||
POM_SCM_DEV_CONNECTION=scm:git@github.com:jenly1314/ZXingLite.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
|
||||
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
POM_LICENSE_DIST=repo
|
||||
|
||||
POM_DEVELOPER_ID=jenly
|
||||
POM_DEVELOPER_NAME=Jenly Yu
|
||||
POM_DEVELOPER_URL=https://github.com/jenly1314/
|
||||
|
||||
RELEASE_REPOSITORY_URL=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/
|
||||
SNAPSHOT_REPOSITORY_URL=https://s01.oss.sonatype.org/content/repositories/snapshots/
|
||||
RELEASE_SIGNING_ENABLED=false
|
||||
|
||||
RELEASE_SIGNING_ENABLED=true
|
||||
|
||||
mavenCentralUsername=jenly
|
||||
mavenCentralPassword=qq1314
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
//App
|
||||
def app_version = [:]
|
||||
app_version.versionCode = 32
|
||||
app_version.versionName = "2.1.1"
|
||||
app_version.versionCode = 33
|
||||
app_version.versionName = "2.2.0"
|
||||
ext.app_version = app_version
|
||||
|
||||
//build version
|
||||
def build_versions = [:]
|
||||
build_versions.minSdk = 21
|
||||
build_versions.targetSdk = 29
|
||||
build_versions.compileSdk = 29
|
||||
build_versions.buildTools = "29.0.3"
|
||||
build_versions.targetSdk = 31
|
||||
build_versions.compileSdk = 31
|
||||
build_versions.buildTools = "31.0.0"
|
||||
ext.build_versions = build_versions
|
||||
|
||||
ext.deps = [:]
|
||||
@@ -19,7 +19,7 @@ def versions = [:]
|
||||
//AndroidX
|
||||
versions.material = "1.2.0"
|
||||
versions.appcompat = "1.1.0"
|
||||
versions.constraintLayout = "1.1.3"
|
||||
versions.constraintLayout = "2.0.4"
|
||||
|
||||
//test
|
||||
versions.junit = "1.1.0"
|
||||
@@ -28,15 +28,15 @@ versions.runner = "1.2.0"
|
||||
versions.espresso = "3.2.0"
|
||||
|
||||
versions.bintray_release = "0.9.2"
|
||||
versions.mavenPublish = '0.13.0'
|
||||
versions.gralde = "3.6.3"
|
||||
versions.mavenPublish = '0.18.0'
|
||||
versions.gralde = "4.2.2"
|
||||
versions.kotlin = "1.4.10"
|
||||
versions.coreKtx = "1.3.2"
|
||||
|
||||
//zxing
|
||||
versions.zxing = "3.3.3"
|
||||
|
||||
versions.camerax = "1.0.1"
|
||||
versions.camerax = "1.1.0-rc01"
|
||||
|
||||
versions.easypermissions = "3.0.0"
|
||||
|
||||
@@ -69,7 +69,7 @@ deps.zxing = "com.google.zxing:core:$versions.zxing"
|
||||
deps.camera_core = "androidx.camera:camera-core:$versions.camerax"
|
||||
deps.camera_camera2 = "androidx.camera:camera-camera2:$versions.camerax"
|
||||
deps.camera_lifecycle = "androidx.camera:camera-lifecycle:$versions.camerax"
|
||||
deps.camera_view = "androidx.camera:camera-view:1.0.0-alpha27"
|
||||
deps.camera_view = "androidx.camera:camera-view:$versions.camerax"
|
||||
|
||||
|
||||
//permission
|
||||
|
||||
@@ -2,13 +2,9 @@
|
||||
package="com.king.zxing">
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
<uses-permission android:name="android.permission.FLASHLIGHT"/>
|
||||
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application>
|
||||
|
||||
</application>
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.google.zxing.Result;
|
||||
import com.king.zxing.util.LogUtils;
|
||||
import com.king.zxing.util.PermissionUtils;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@@ -45,9 +44,8 @@ public class CaptureActivity extends AppCompatActivity implements CameraScan.OnS
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
int layoutId = getLayoutId();
|
||||
if(isContentView(layoutId)){
|
||||
setContentView(layoutId);
|
||||
if(isContentView()){
|
||||
setContentView(getLayoutId());
|
||||
}
|
||||
initUI();
|
||||
}
|
||||
@@ -154,10 +152,9 @@ public class CaptureActivity extends AppCompatActivity implements CameraScan.OnS
|
||||
|
||||
/**
|
||||
* 返回true时会自动初始化{@link #setContentView(int)},返回为false是需自己去初始化{@link #setContentView(int)}
|
||||
* @param layoutId
|
||||
* @return 默认返回true
|
||||
*/
|
||||
public boolean isContentView(@LayoutRes int layoutId){
|
||||
public boolean isContentView(){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.google.zxing.Result;
|
||||
import com.king.zxing.util.LogUtils;
|
||||
import com.king.zxing.util.PermissionUtils;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.camera.view.PreviewView;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@@ -57,8 +56,7 @@ public class CaptureFragment extends Fragment implements CameraScan.OnScanResult
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
int layoutId = getLayoutId();
|
||||
if(isContentView(layoutId)){
|
||||
if(isContentView()){
|
||||
mRootView = createRootView(inflater,container);
|
||||
}
|
||||
initUI();
|
||||
@@ -165,10 +163,9 @@ public class CaptureFragment extends Fragment implements CameraScan.OnScanResult
|
||||
|
||||
/**
|
||||
* 返回true时会自动初始化{@link #createRootView(LayoutInflater, ViewGroup)},返回为false是需自己去初始化{@link #createRootView(LayoutInflater, ViewGroup)}
|
||||
* @param layoutId
|
||||
* @return 默认返回true
|
||||
*/
|
||||
public boolean isContentView(@LayoutRes int layoutId){
|
||||
public boolean isContentView(){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.king.zxing;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ScaleGestureDetector;
|
||||
@@ -241,6 +242,7 @@ public class DefaultCameraScan extends CameraScan {
|
||||
|
||||
//图像分析
|
||||
ImageAnalysis imageAnalysis = mCameraConfig.options(new ImageAnalysis.Builder()
|
||||
.setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888)
|
||||
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST));
|
||||
imageAnalysis.setAnalyzer(Executors.newSingleThreadExecutor(), image -> {
|
||||
if(isAnalyze && !isAnalyzeResult && mAnalyzer != null){
|
||||
@@ -433,7 +435,7 @@ public class DefaultCameraScan extends CameraScan {
|
||||
if(mCamera != null){
|
||||
return mCamera.getCameraInfo().hasFlashUnit();
|
||||
}
|
||||
return false;
|
||||
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,8 +47,9 @@ public abstract class ImageAnalyzer implements Analyzer {
|
||||
return analyze(rotatedData,height,width);
|
||||
}
|
||||
return analyze(data,width,height);
|
||||
}else{
|
||||
LogUtils.w("imageFormat: " + image.getFormat());
|
||||
}
|
||||
LogUtils.w("imageFormat: " + image.getFormat());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,15 @@ import android.content.Context;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Build;
|
||||
import android.os.VibrationEffect;
|
||||
import android.os.Vibrator;
|
||||
|
||||
import com.king.zxing.R;
|
||||
import com.king.zxing.util.LogUtils;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.lang.annotation.ElementType;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
@@ -67,8 +70,12 @@ public final class BeepManager implements MediaPlayer.OnErrorListener, Closeable
|
||||
if (playBeep && mediaPlayer != null) {
|
||||
mediaPlayer.start();
|
||||
}
|
||||
if (vibrate) {
|
||||
vibrator.vibrate(VIBRATE_DURATION);
|
||||
if (vibrate && vibrator.hasVibrator()) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
vibrator.vibrate(VibrationEffect.createOneShot(VIBRATE_DURATION, VibrationEffect.DEFAULT_AMPLITUDE));
|
||||
} else {
|
||||
vibrator.vibrate(VIBRATE_DURATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user