发布v3.0.0
This commit is contained in:
@@ -24,34 +24,21 @@
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.king.zxing.CaptureActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
|
||||
<activity
|
||||
android:name=".EasyCaptureActivity"
|
||||
android:name=".FullScreenQRCodeScanActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
<activity
|
||||
android:name=".CustomCaptureActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
android:theme="@style/CameraScanTheme"/>
|
||||
|
||||
<activity
|
||||
android:name=".CaptureFragmentActivity"
|
||||
android:name=".MultiFormatScanActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
android:theme="@style/CameraScanTheme"/>
|
||||
|
||||
<activity
|
||||
android:name=".CustomFullScanActivity"
|
||||
android:name=".QRCodeScanActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
|
||||
<activity
|
||||
android:name=".QRCodeActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
android:theme="@style/CameraScanTheme"/>
|
||||
|
||||
<activity
|
||||
android:name=".CodeActivity"
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.king.zxing.app;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.king.zxing.CaptureFragment;
|
||||
import com.king.zxing.app.util.StatusBarUtils;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
/**
|
||||
* Fragment扫码
|
||||
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
public class CaptureFragmentActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.fragment_activity);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
StatusBarUtils.immersiveStatusBar(this,toolbar,0.2f);
|
||||
TextView tvTitle = findViewById(R.id.tvTitle);
|
||||
tvTitle.setText(getIntent().getStringExtra(MainActivity.KEY_TITLE));
|
||||
|
||||
replaceFragment(CaptureFragment.newInstance());
|
||||
}
|
||||
|
||||
public void replaceFragment(Fragment fragment){
|
||||
replaceFragment( R.id.fragmentContent,fragment);
|
||||
}
|
||||
|
||||
public void replaceFragment(@IdRes int id, Fragment fragment) {
|
||||
getSupportFragmentManager().beginTransaction().replace(id, fragment).commit();
|
||||
}
|
||||
|
||||
public void onClick(View v){
|
||||
switch (v.getId()){
|
||||
case R.id.ivLeft:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,29 +25,39 @@ import android.widget.TextView;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.king.zxing.util.CodeUtils;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
/**
|
||||
* 生成条形码/二维码示例
|
||||
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
public class CodeActivity extends AppCompatActivity {
|
||||
|
||||
private TextView tvTitle;
|
||||
|
||||
private TextView tvBarcodeFormat;
|
||||
private ImageView ivCode;
|
||||
|
||||
private ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.code_activity);
|
||||
ivCode = findViewById(R.id.ivCode);
|
||||
tvTitle = findViewById(R.id.tvTitle);
|
||||
tvBarcodeFormat = findViewById(R.id.tvBarcodeFormat);
|
||||
tvTitle.setText(getIntent().getStringExtra(MainActivity.KEY_TITLE));
|
||||
boolean isQRCode = getIntent().getBooleanExtra(MainActivity.KEY_IS_QR_CODE,false);
|
||||
|
||||
if(isQRCode){
|
||||
tvBarcodeFormat.setText("BarcodeFormat: QR_CODE");
|
||||
createQRCode(getString(R.string.app_name));
|
||||
}else{
|
||||
tvBarcodeFormat.setText("BarcodeFormat: CODE_128");
|
||||
createBarCode("1234567890");
|
||||
}
|
||||
}
|
||||
@@ -57,7 +67,7 @@ public class CodeActivity extends AppCompatActivity {
|
||||
* @param content
|
||||
*/
|
||||
private void createQRCode(String content){
|
||||
new Thread(() -> {
|
||||
executor.execute(() -> {
|
||||
//生成二维码相关放在子线程里面
|
||||
Bitmap logo = BitmapFactory.decodeResource(getResources(),R.drawable.logo);
|
||||
Bitmap bitmap = CodeUtils.createQRCode(content,600,logo);
|
||||
@@ -65,7 +75,7 @@ public class CodeActivity extends AppCompatActivity {
|
||||
//显示二维码
|
||||
ivCode.setImageBitmap(bitmap);
|
||||
});
|
||||
}).start();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -74,18 +84,17 @@ public class CodeActivity extends AppCompatActivity {
|
||||
* @param content
|
||||
*/
|
||||
private void createBarCode(String content){
|
||||
new Thread(() -> {
|
||||
executor.execute(() -> {
|
||||
//生成条形码相关放在子线程里面
|
||||
Bitmap bitmap = CodeUtils.createBarCode(content, BarcodeFormat.CODE_128,800,200,null,true);
|
||||
runOnUiThread(()->{
|
||||
//显示条形码
|
||||
ivCode.setImageBitmap(bitmap);
|
||||
});
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void onClick(View v){
|
||||
switch (v.getId()){
|
||||
case R.id.ivLeft:
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Jenly Yu
|
||||
*
|
||||
* 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.zxing.app;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.king.zxing.CameraScan;
|
||||
import com.king.zxing.CaptureActivity;
|
||||
import com.king.zxing.DecodeConfig;
|
||||
import com.king.zxing.DecodeFormatManager;
|
||||
import com.king.zxing.analyze.MultiFormatAnalyzer;
|
||||
import com.king.zxing.app.util.StatusBarUtils;
|
||||
import com.king.zxing.config.ResolutionCameraConfig;
|
||||
|
||||
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
/**
|
||||
* 自定义继承CaptureActivity
|
||||
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
public class CustomCaptureActivity extends CaptureActivity {
|
||||
|
||||
private boolean isContinuousScan;
|
||||
|
||||
private Toast toast;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.custom_capture_activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
|
||||
super.onCreate(icicle);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
StatusBarUtils.immersiveStatusBar(this,toolbar,0.2f);
|
||||
TextView tvTitle = findViewById(R.id.tvTitle);
|
||||
tvTitle.setText(getIntent().getStringExtra(MainActivity.KEY_TITLE));
|
||||
|
||||
isContinuousScan = getIntent().getBooleanExtra(MainActivity.KEY_IS_CONTINUOUS,false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initCameraScan() {
|
||||
super.initCameraScan();
|
||||
//初始化解码配置
|
||||
DecodeConfig decodeConfig = new DecodeConfig();
|
||||
decodeConfig.setHints(DecodeFormatManager.ALL_HINTS)////设置解码
|
||||
.setSupportVerticalCode(true)//设置是否支持扫垂直的条码 (增强识别率,相应的也会增加性能消耗)
|
||||
.setSupportLuminanceInvert(true)//设置是否支持识别反色码,黑白颜色反转(增强识别率,相应的也会增加性能消耗)
|
||||
.setAreaRectRatio(0.8f)//设置识别区域比例,默认0.8,设置的比例最终会在预览区域裁剪基于此比例的一个矩形进行扫码识别
|
||||
// .setAreaRectVerticalOffset(0)//设置识别区域垂直方向偏移量,默认为0,为0表示居中,可以为负数
|
||||
// .setAreaRectHorizontalOffset(0)//设置识别区域水平方向偏移量,默认为0,为0表示居中,可以为负数
|
||||
.setFullAreaScan(false);//设置是否全区域识别,默认false
|
||||
|
||||
//获取CameraScan,里面有扫码相关的配置设置。CameraScan里面包含部分支持链式调用的方法,即调用返回是CameraScan本身的一些配置建议在startCamera之前调用。
|
||||
getCameraScan().setPlayBeep(true)//设置是否播放音效,默认为false
|
||||
.setVibrate(true)//设置是否震动,默认为false
|
||||
// .setCameraConfig(new CameraConfig())//设置相机配置信息,CameraConfig可覆写options方法自定义配置
|
||||
// .setCameraConfig(new ResolutionCameraConfig(this))//设置CameraConfig,可以根据自己的需求去自定义配置
|
||||
.setNeedAutoZoom(false)//二维码太小时可自动缩放,默认为false
|
||||
.setNeedTouchZoom(true)//支持多指触摸捏合缩放,默认为true
|
||||
.setDarkLightLux(45f)//设置光线足够暗的阈值(单位:lux),需要通过{@link #bindFlashlightView(View)}绑定手电筒才有效
|
||||
.setBrightLightLux(100f)//设置光线足够明亮的阈值(单位:lux),需要通过{@link #bindFlashlightView(View)}绑定手电筒才有效
|
||||
.bindFlashlightView(ivFlashlight)//绑定手电筒,绑定后可根据光线传感器,动态显示或隐藏手电筒按钮
|
||||
.setOnScanResultCallback(this)//设置扫码结果回调,需要自己处理或者需要连扫时,可设置回调,自己去处理相关逻辑
|
||||
.setAnalyzer(new MultiFormatAnalyzer(decodeConfig))//设置分析器,DecodeConfig可以配置一些解码时的配置信息,如果内置的不满足您的需求,你也可以自定义实现,
|
||||
.setAnalyzeImage(true);//设置是否分析图片,默认为true。如果设置为false,相当于关闭了扫码识别功能
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码结果回调
|
||||
* @param result
|
||||
* @return 返回false表示不拦截,将关闭扫码界面并将结果返回给调用界面;
|
||||
* 返回true表示拦截,需自己处理逻辑。当isAnalyze为true时,默认会继续分析图像(也就是连扫)。
|
||||
* 如果只是想拦截扫码结果回调,并不想继续分析图像(不想连扫),请在拦截扫码逻辑处通过调
|
||||
* 用{@link CameraScan#setAnalyzeImage(boolean)},
|
||||
* 因为{@link CameraScan#setAnalyzeImage(boolean)}方法能动态控制是否继续分析图像。
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public boolean onScanResultCallback(Result result) {
|
||||
if(isContinuousScan){
|
||||
showToast(result.getText());
|
||||
}
|
||||
/*
|
||||
* 因为setAnalyzeImage方法能动态控制是否继续分析图像。
|
||||
*
|
||||
* 1. 因为分析图像默认为true,如果想支持连扫,返回true即可。
|
||||
* 当连扫的处理逻辑比较复杂时,请在处理逻辑前调用getCameraScan().setAnalyzeImage(false),
|
||||
* 来停止分析图像,等逻辑处理完后再调用getCameraScan().setAnalyzeImage(true)来继续分析图像。
|
||||
*
|
||||
* 2. 如果只是想拦截扫码结果回调自己处理逻辑,但并不想继续分析图像(即不想连扫),可通过
|
||||
* 调用getCameraScan().setAnalyzeImage(false)来停止分析图像。
|
||||
*/
|
||||
return isContinuousScan;
|
||||
}
|
||||
|
||||
private void showToast(String text){
|
||||
if(toast != null){
|
||||
toast.cancel();
|
||||
}
|
||||
toast = Toast.makeText(this,text,Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
public void onClick(View v){
|
||||
switch (v.getId()){
|
||||
case R.id.ivLeft:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
package com.king.zxing.app;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.king.zxing.CameraScan;
|
||||
import com.king.zxing.DecodeConfig;
|
||||
import com.king.zxing.DecodeFormatManager;
|
||||
import com.king.zxing.DefaultCameraScan;
|
||||
import com.king.zxing.ViewfinderView;
|
||||
import com.king.zxing.analyze.MultiFormatAnalyzer;
|
||||
import com.king.zxing.app.util.StatusBarUtils;
|
||||
import com.king.zxing.config.ResolutionCameraConfig;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.camera.view.PreviewView;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
/**
|
||||
* 自定义扫码:当直接使用CaptureActivity
|
||||
* 自定义扫码,切记自定义扫码需在{@link Activity}或者{@link Fragment}相对应的生命周期里面调用{@link #mCameraScan}对应的生命周期
|
||||
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
public class CustomFullScanActivity extends AppCompatActivity implements CameraScan.OnScanResultCallback {
|
||||
|
||||
private boolean isContinuousScan;
|
||||
|
||||
private CameraScan mCameraScan;
|
||||
|
||||
private PreviewView previewView;
|
||||
|
||||
private ViewfinderView viewfinderView;
|
||||
|
||||
private View ivFlash;
|
||||
|
||||
private Toast toast;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setContentView(R.layout.custom_activity);
|
||||
|
||||
initUI();
|
||||
}
|
||||
|
||||
private void initUI(){
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
StatusBarUtils.immersiveStatusBar(this,toolbar,0.2f);
|
||||
TextView tvTitle = findViewById(R.id.tvTitle);
|
||||
tvTitle.setText(getIntent().getStringExtra(MainActivity.KEY_TITLE));
|
||||
|
||||
|
||||
previewView = findViewById(R.id.previewView);
|
||||
viewfinderView = findViewById(R.id.viewfinderView);
|
||||
ivFlash = findViewById(R.id.ivFlash);
|
||||
ivFlash.setVisibility(View.INVISIBLE);
|
||||
|
||||
isContinuousScan = getIntent().getBooleanExtra(MainActivity.KEY_IS_CONTINUOUS,false);
|
||||
|
||||
//初始化解码配置
|
||||
DecodeConfig decodeConfig = new DecodeConfig();
|
||||
decodeConfig.setHints(DecodeFormatManager.QR_CODE_HINTS)//如果只有识别二维码的需求,这样设置效率会更高,不设置默认为DecodeFormatManager.DEFAULT_HINTS
|
||||
.setFullAreaScan(true);//设置是否全区域识别,默认false
|
||||
|
||||
mCameraScan = new DefaultCameraScan(this,previewView);
|
||||
mCameraScan.setOnScanResultCallback(this)
|
||||
.setAnalyzer(new MultiFormatAnalyzer(decodeConfig))
|
||||
.setVibrate(true)
|
||||
.setCameraConfig(new ResolutionCameraConfig(this, ResolutionCameraConfig.IMAGE_QUALITY_720P))
|
||||
.startCamera();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
mCameraScan.release();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码结果回调
|
||||
* @param result 扫码结果
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onScanResultCallback(Result result) {
|
||||
if(isContinuousScan){
|
||||
showToast(result.getText());
|
||||
}
|
||||
//如果需支持连扫,返回true即可
|
||||
return isContinuousScan;
|
||||
}
|
||||
|
||||
private void showToast(String text){
|
||||
if(toast == null){
|
||||
toast = Toast.makeText(this,text,Toast.LENGTH_SHORT);
|
||||
}else{
|
||||
toast.setDuration(Toast.LENGTH_SHORT);
|
||||
toast.setText(text);
|
||||
}
|
||||
toast.show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void onClick(View v){
|
||||
switch (v.getId()){
|
||||
case R.id.ivLeft:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Jenly Yu
|
||||
*
|
||||
* 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.zxing.app;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.king.zxing.CaptureActivity;
|
||||
import com.king.zxing.app.util.StatusBarUtils;
|
||||
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
/**
|
||||
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
public class EasyCaptureActivity extends CaptureActivity {
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.easy_capture_activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
StatusBarUtils.immersiveStatusBar(this,toolbar,0.2f);
|
||||
TextView tvTitle = findViewById(R.id.tvTitle);
|
||||
tvTitle.setText(getIntent().getStringExtra(MainActivity.KEY_TITLE));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initCameraScan() {
|
||||
super.initCameraScan();
|
||||
getCameraScan()
|
||||
.setPlayBeep(true)
|
||||
.setVibrate(true);
|
||||
}
|
||||
|
||||
public void onClick(View v){
|
||||
switch (v.getId()){
|
||||
case R.id.ivLeft:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.king.zxing.app
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.widget.Toast
|
||||
import com.google.zxing.Result
|
||||
import com.king.camera.scan.AnalyzeResult
|
||||
import com.king.camera.scan.CameraScan
|
||||
import com.king.camera.scan.analyze.Analyzer
|
||||
import com.king.camera.scan.util.PointUtils
|
||||
import com.king.view.viewfinderview.ViewfinderView.ViewfinderStyle
|
||||
import com.king.zxing.DecodeConfig
|
||||
import com.king.zxing.DecodeFormatManager
|
||||
import com.king.zxing.BarcodeCameraScanActivity
|
||||
import com.king.zxing.analyze.QRCodeAnalyzer
|
||||
|
||||
/**
|
||||
* 扫二维码全屏识别示例
|
||||
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
class FullScreenQRCodeScanActivity : BarcodeCameraScanActivity() {
|
||||
|
||||
override fun initUI() {
|
||||
super.initUI()
|
||||
|
||||
// 设置取景框样式
|
||||
viewfinderView.setViewfinderStyle(ViewfinderStyle.POPULAR)
|
||||
|
||||
}
|
||||
|
||||
|
||||
override fun initCameraScan(cameraScan: CameraScan<Result>) {
|
||||
super.initCameraScan(cameraScan)
|
||||
// 根据需要设置CameraScan相关配置
|
||||
cameraScan.setPlayBeep(true)
|
||||
}
|
||||
|
||||
override fun createAnalyzer(): Analyzer<Result>? {
|
||||
// 初始化解码配置
|
||||
val decodeConfig = DecodeConfig().apply {
|
||||
// 如果只有识别二维码的需求,这样设置效率会更高,不设置默认为DecodeFormatManager.DEFAULT_HINTS
|
||||
hints = DecodeFormatManager.QR_CODE_HINTS
|
||||
// 设置是否全区域识别,默认false
|
||||
isFullAreaScan = true
|
||||
}
|
||||
// BarcodeCameraScanActivity默认使用的MultiFormatAnalyzer,这里可以改为使用QRCodeAnalyzer
|
||||
return QRCodeAnalyzer(decodeConfig)
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局ID;通过覆写此方法可以自定义布局
|
||||
*
|
||||
* @return 布局ID
|
||||
*/
|
||||
override fun getLayoutId(): Int {
|
||||
return super.getLayoutId()
|
||||
}
|
||||
|
||||
override fun onScanResultCallback(result: AnalyzeResult<Result>) {
|
||||
// 停止分析
|
||||
cameraScan.setAnalyzeImage(false)
|
||||
// 显示结果点
|
||||
displayResultPoint(result)
|
||||
|
||||
// 返回结果
|
||||
val intent = Intent()
|
||||
intent.putExtra(CameraScan.SCAN_RESULT, result.result.text)
|
||||
setResult(Activity.RESULT_OK, intent)
|
||||
finish()
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示结果点
|
||||
*/
|
||||
private fun displayResultPoint(result: AnalyzeResult<Result>) {
|
||||
val frameMetadata = result.frameMetadata
|
||||
var width = frameMetadata.width
|
||||
var height = frameMetadata.height
|
||||
if (frameMetadata.rotation == 90 || frameMetadata.rotation == 270) {
|
||||
width = frameMetadata.height
|
||||
height = frameMetadata.width
|
||||
}
|
||||
val resultPoints = result.result.resultPoints
|
||||
val size = resultPoints.size
|
||||
if (size > 0) {
|
||||
var x = 0f
|
||||
var y = 0f
|
||||
resultPoints.forEach {
|
||||
x += it.x
|
||||
y += it.y
|
||||
}
|
||||
var centerX = x / size
|
||||
var centerY = y / size
|
||||
//将实际的结果中心点坐标转换成界面预览的坐标
|
||||
val point = PointUtils.transform(
|
||||
centerX.toInt(),
|
||||
centerY.toInt(),
|
||||
width,
|
||||
height,
|
||||
viewfinderView.width,
|
||||
viewfinderView.height
|
||||
)
|
||||
//显示结果点信息
|
||||
viewfinderView.showResultPoints(listOf(point))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.king.zxing.app;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.provider.MediaStore;
|
||||
@@ -25,52 +24,30 @@ import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.king.zxing.CameraScan;
|
||||
import com.king.zxing.CaptureActivity;
|
||||
import com.king.camera.scan.CameraScan;
|
||||
import com.king.camera.scan.util.LogUtils;
|
||||
import com.king.camera.scan.util.PermissionUtils;
|
||||
import com.king.zxing.util.CodeUtils;
|
||||
import com.king.zxing.util.LogUtils;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.app.ActivityOptionsCompat;
|
||||
import pub.devrel.easypermissions.AfterPermissionGranted;
|
||||
import pub.devrel.easypermissions.EasyPermissions;
|
||||
|
||||
/**
|
||||
* 扫码Demo示例说明
|
||||
*
|
||||
* 快速实现扫码识别有以下几种方式:
|
||||
*
|
||||
* 1、直接使用CaptureActivity或者CaptureFragment。(默认的扫码实现)
|
||||
*
|
||||
* 2、通过继承CaptureActivity或者CaptureFragment并自定义布局。(适用于大多场景,并无需关心扫码相关逻辑,自定义布局时需覆写getLayoutId方法)
|
||||
*
|
||||
* 3、在你项目的Activity或者Fragment中实例化一个CameraScan即可。(适用于想在扫码界面写交互逻辑,又因为项目架构或其它原因,无法直接或间接继承CaptureActivity或CaptureFragment时使用)
|
||||
*
|
||||
* 4、继承CameraScan自己实现一个,可参照默认实现类DefaultCameraScan,其它步骤同方式3。(扩展高级用法,谨慎使用)
|
||||
*
|
||||
* 扫码示例
|
||||
*/
|
||||
public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks{
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public static final String KEY_TITLE = "key_title";
|
||||
public static final String KEY_IS_QR_CODE = "key_code";
|
||||
public static final String KEY_IS_CONTINUOUS = "key_continuous_scan";
|
||||
|
||||
public static final int REQUEST_CODE_SCAN = 0X01;
|
||||
public static final int REQUEST_CODE_PHOTO = 0X02;
|
||||
public static final int REQUEST_CODE_SCAN = 0x01;
|
||||
public static final int REQUEST_CODE_PHOTO = 0x02;
|
||||
|
||||
public static final int RC_CAMERA = 0X01;
|
||||
|
||||
public static final int RC_READ_PHOTO = 0X02;
|
||||
|
||||
private Class<?> cls;
|
||||
private String title;
|
||||
private boolean isContinuousScan;
|
||||
public static final int REQUEST_CODE_READ_EXTERNAL_STORAGE = 0x99;
|
||||
|
||||
private Toast toast;
|
||||
|
||||
@@ -86,8 +63,8 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if(resultCode == RESULT_OK && data!=null){
|
||||
switch (requestCode){
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_SCAN:
|
||||
String result = CameraScan.parseScanResult(data);
|
||||
showToast(result);
|
||||
@@ -100,23 +77,24 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
}
|
||||
}
|
||||
|
||||
private void showToast(String text){
|
||||
if(toast != null){
|
||||
toast.cancel();
|
||||
private void showToast(String text) {
|
||||
if (toast == null) {
|
||||
toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
|
||||
}else {
|
||||
toast.setText(text);
|
||||
}
|
||||
toast = Toast.makeText(this,text,Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
private void parsePhoto(Intent data){
|
||||
private void parsePhoto(Intent data) {
|
||||
try {
|
||||
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),data.getData());
|
||||
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), data.getData());
|
||||
//异步解析
|
||||
asyncThread(() -> {
|
||||
final String result = CodeUtils.parseCode(bitmap);
|
||||
runOnUiThread(() -> {
|
||||
LogUtils.d("result:" + result);
|
||||
Toast.makeText(getContext(),result,Toast.LENGTH_SHORT).show();
|
||||
showToast(result);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -127,133 +105,86 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
|
||||
}
|
||||
|
||||
private Context getContext(){
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
// Forward results to EasyPermissions
|
||||
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionsGranted(int requestCode, List<String> list) {
|
||||
// Some permissions have been granted
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionsDenied(int requestCode, List<String> list) {
|
||||
// Some permissions have been denied
|
||||
// ...
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测拍摄权限
|
||||
*/
|
||||
@AfterPermissionGranted(RC_CAMERA)
|
||||
private void checkCameraPermissions(){
|
||||
String[] perms = {Manifest.permission.CAMERA};
|
||||
if (EasyPermissions.hasPermissions(this, perms)) {//有权限
|
||||
startScan(cls,title);
|
||||
} else {
|
||||
// Do not have permissions, request them now
|
||||
EasyPermissions.requestPermissions(this, getString(R.string.permission_camera),
|
||||
RC_CAMERA, perms);
|
||||
if (requestCode == REQUEST_CODE_READ_EXTERNAL_STORAGE && PermissionUtils.requestPermissionsResult(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
permissions,
|
||||
grantResults)) {
|
||||
startPickPhoto();
|
||||
}
|
||||
}
|
||||
|
||||
private void asyncThread(Runnable runnable){
|
||||
private void asyncThread(Runnable runnable) {
|
||||
executor.execute(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码
|
||||
*
|
||||
* @param cls
|
||||
* @param title
|
||||
*/
|
||||
private void startScan(Class<?> cls,String title){
|
||||
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeCustomAnimation(this,R.anim.in,R.anim.out);
|
||||
private void startScan(Class<?> cls) {
|
||||
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.in, R.anim.out);
|
||||
Intent intent = new Intent(this, cls);
|
||||
intent.putExtra(KEY_TITLE,title);
|
||||
intent.putExtra(KEY_IS_CONTINUOUS,isContinuousScan);
|
||||
ActivityCompat.startActivityForResult(this,intent,REQUEST_CODE_SCAN,optionsCompat.toBundle());
|
||||
ActivityCompat.startActivityForResult(this, intent, REQUEST_CODE_SCAN, optionsCompat.toBundle());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成二维码/条形码
|
||||
*
|
||||
* @param isQRCode
|
||||
*/
|
||||
private void startCode(boolean isQRCode){
|
||||
Intent intent = new Intent(this,CodeActivity.class);
|
||||
intent.putExtra(KEY_IS_QR_CODE,isQRCode);
|
||||
intent.putExtra(KEY_TITLE,isQRCode ? getString(R.string.qr_code) : getString(R.string.bar_code));
|
||||
private void startGenerateCodeActivity(boolean isQRCode, String title) {
|
||||
Intent intent = new Intent(this, CodeActivity.class);
|
||||
intent.putExtra(KEY_IS_QR_CODE, isQRCode);
|
||||
intent.putExtra(KEY_TITLE, title);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void startPhotoCode(){
|
||||
/**
|
||||
* 点击选择图片识别 - 进行动态权限校验
|
||||
*/
|
||||
private void pickPhotoClicked() {
|
||||
if (PermissionUtils.checkPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
||||
startPickPhoto();
|
||||
} else {
|
||||
PermissionUtils.requestPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE, REQUEST_CODE_READ_EXTERNAL_STORAGE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始选择图片
|
||||
*/
|
||||
private void startPickPhoto() {
|
||||
Intent pickIntent = new Intent(Intent.ACTION_PICK,
|
||||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
pickIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
|
||||
startActivityForResult(pickIntent, REQUEST_CODE_PHOTO);
|
||||
}
|
||||
|
||||
@AfterPermissionGranted(RC_READ_PHOTO)
|
||||
private void checkExternalStoragePermissions(){
|
||||
String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
||||
if (EasyPermissions.hasPermissions(this, perms)) {//有权限
|
||||
startPhotoCode();
|
||||
}else{
|
||||
EasyPermissions.requestPermissions(this, getString(R.string.permission_external_storage),
|
||||
RC_READ_PHOTO, perms);
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(View v){
|
||||
isContinuousScan = false;
|
||||
switch (v.getId()){
|
||||
case R.id.btn0:
|
||||
this.cls = CaptureActivity.class;
|
||||
this.title = ((Button)v).getText().toString();
|
||||
checkCameraPermissions();
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.btnMultiFormat:
|
||||
startScan(MultiFormatScanActivity.class);
|
||||
break;
|
||||
case R.id.btn1:
|
||||
this.cls = CustomCaptureActivity.class;
|
||||
this.title = ((Button)v).getText().toString();
|
||||
isContinuousScan = true;
|
||||
checkCameraPermissions();
|
||||
case R.id.btnQRCode:
|
||||
startScan(QRCodeScanActivity.class);
|
||||
break;
|
||||
case R.id.btn2:
|
||||
this.cls = CaptureFragmentActivity.class;
|
||||
this.title = ((Button)v).getText().toString();
|
||||
checkCameraPermissions();
|
||||
case R.id.btnFullQRCode:
|
||||
startScan(FullScreenQRCodeScanActivity.class);
|
||||
break;
|
||||
case R.id.btn3:
|
||||
this.cls = EasyCaptureActivity.class;
|
||||
this.title = ((Button)v).getText().toString();
|
||||
checkCameraPermissions();
|
||||
case R.id.btnPickPhoto:
|
||||
pickPhotoClicked();
|
||||
break;
|
||||
case R.id.btn4:
|
||||
this.cls = CustomFullScanActivity.class;
|
||||
this.title = ((Button)v).getText().toString();
|
||||
checkCameraPermissions();
|
||||
case R.id.btnGenerateQrCode:
|
||||
startGenerateCodeActivity(true, ((Button) v).getText().toString());
|
||||
break;
|
||||
case R.id.btn5:
|
||||
startCode(false);
|
||||
break;
|
||||
case R.id.btn6:
|
||||
startCode(true);
|
||||
break;
|
||||
case R.id.btn7:
|
||||
checkExternalStoragePermissions();
|
||||
break;
|
||||
case R.id.btn8:
|
||||
this.cls = QRCodeActivity.class;
|
||||
this.title = ((Button)v).getText().toString();
|
||||
checkCameraPermissions();
|
||||
case R.id.btnGenerateBarcode:
|
||||
startGenerateCodeActivity(false, ((Button) v).getText().toString());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.king.zxing.app
|
||||
|
||||
import android.widget.Toast
|
||||
import com.google.zxing.Result
|
||||
import com.king.camera.scan.AnalyzeResult
|
||||
import com.king.camera.scan.CameraScan
|
||||
import com.king.camera.scan.analyze.Analyzer
|
||||
import com.king.zxing.DecodeConfig
|
||||
import com.king.zxing.BarcodeCameraScanActivity
|
||||
import com.king.zxing.analyze.MultiFormatAnalyzer
|
||||
|
||||
/**
|
||||
* 连续扫码(识别多种格式)示例
|
||||
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
class MultiFormatScanActivity : BarcodeCameraScanActivity() {
|
||||
|
||||
var toast: Toast? = null
|
||||
|
||||
override fun initCameraScan(cameraScan: CameraScan<Result>) {
|
||||
super.initCameraScan(cameraScan)
|
||||
// 根据需要设置CameraScan相关配置
|
||||
cameraScan.setPlayBeep(true)
|
||||
}
|
||||
|
||||
override fun createAnalyzer(): Analyzer<Result>? {
|
||||
// 初始化解码配置
|
||||
val decodeConfig = DecodeConfig().apply {
|
||||
// 设置是否支持扫垂直的条码
|
||||
isSupportVerticalCode = true
|
||||
// 设置是否支持识别反色码,黑白颜色反转
|
||||
isSupportLuminanceInvert = true
|
||||
}
|
||||
// 多格式分析器(支持的条码格式主要包含:一维码和二维码)
|
||||
return MultiFormatAnalyzer(decodeConfig)
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局ID;通过覆写此方法可以自定义布局
|
||||
*
|
||||
* @return 布局ID
|
||||
*/
|
||||
override fun getLayoutId(): Int {
|
||||
return super.getLayoutId()
|
||||
}
|
||||
|
||||
override fun onScanResultCallback(result: AnalyzeResult<Result>) {
|
||||
// 停止分析
|
||||
cameraScan.setAnalyzeImage(false)
|
||||
// 处理扫码结果相关逻辑(此处弹Toast只是为了演示)
|
||||
showToast(result.result.text)
|
||||
// 继续分析
|
||||
cameraScan.setAnalyzeImage(true)
|
||||
}
|
||||
|
||||
private fun showToast(text: String) {
|
||||
if(toast == null) {
|
||||
toast = Toast.makeText(this, text, Toast.LENGTH_SHORT)
|
||||
} else {
|
||||
toast?.setText(text)
|
||||
}
|
||||
toast?.show()
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package com.king.zxing.app;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.king.zxing.CameraScan;
|
||||
import com.king.zxing.CaptureActivity;
|
||||
import com.king.zxing.DecodeConfig;
|
||||
import com.king.zxing.DecodeFormatManager;
|
||||
import com.king.zxing.analyze.MultiFormatAnalyzer;
|
||||
import com.king.zxing.app.util.StatusBarUtils;
|
||||
import com.king.zxing.config.AspectRatioCameraConfig;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
public class QRCodeActivity extends CaptureActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
StatusBarUtils.immersiveStatusBar(this,toolbar,0.2f);
|
||||
TextView tvTitle = findViewById(R.id.tvTitle);
|
||||
tvTitle.setText(getIntent().getStringExtra(MainActivity.KEY_TITLE));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.qr_code_activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initCameraScan() {
|
||||
super.initCameraScan();
|
||||
|
||||
//初始化解码配置
|
||||
DecodeConfig decodeConfig = new DecodeConfig();
|
||||
decodeConfig.setHints(DecodeFormatManager.QR_CODE_HINTS)//如果只有识别二维码的需求,这样设置效率会更高,不设置默认为DecodeFormatManager.DEFAULT_HINTS
|
||||
.setFullAreaScan(false)//设置是否全区域识别,默认false
|
||||
.setAreaRectRatio(0.8f)//设置识别区域比例,默认0.8,设置的比例最终会在预览区域裁剪基于此比例的一个矩形进行扫码识别
|
||||
.setAreaRectVerticalOffset(0)//设置识别区域垂直方向偏移量,默认为0,为0表示居中,可以为负数
|
||||
.setAreaRectHorizontalOffset(0);//设置识别区域水平方向偏移量,默认为0,为0表示居中,可以为负数
|
||||
|
||||
//在启动预览之前,设置分析器,只识别二维码
|
||||
getCameraScan()
|
||||
.setCameraConfig(new AspectRatioCameraConfig(this))//设置相机配置,使用 AspectRatioCameraConfig
|
||||
.setVibrate(true)//设置是否震动,默认为false
|
||||
.setAnalyzer(new MultiFormatAnalyzer(decodeConfig));//设置分析器,如果内置实现的一些分析器不满足您的需求,你也可以自定义去实现
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 扫码结果回调
|
||||
* @param result
|
||||
* @return 返回false表示不拦截,将关闭扫码界面并将结果返回给调用界面;
|
||||
* 返回true表示拦截,需自己处理逻辑。当isAnalyze为true时,默认会继续分析图像(也就是连扫)。
|
||||
* 如果只是想拦截扫码结果回调,并不想继续分析图像(不想连扫),请在拦截扫码逻辑处通过调
|
||||
* 用{@link CameraScan#setAnalyzeImage(boolean)},
|
||||
* 因为{@link CameraScan#setAnalyzeImage(boolean)}方法能动态控制是否继续分析图像。
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public boolean onScanResultCallback(Result result) {
|
||||
/*
|
||||
* 因为setAnalyzeImage方法能动态控制是否继续分析图像。
|
||||
*
|
||||
* 1. 因为分析图像默认为true,如果想支持连扫,返回true即可。
|
||||
* 当连扫的处理逻辑比较复杂时,请在处理逻辑前调用getCameraScan().setAnalyzeImage(false),
|
||||
* 来停止分析图像,等逻辑处理完后再调用getCameraScan().setAnalyzeImage(true)来继续分析图像。
|
||||
*
|
||||
* 2. 如果只是想拦截扫码结果回调自己处理逻辑,但并不想继续分析图像(即不想连扫),可通过
|
||||
* 调用getCameraScan().setAnalyzeImage(false)来停止分析图像。
|
||||
*/
|
||||
return super.onScanResultCallback(result);
|
||||
}
|
||||
|
||||
public void onClick(View v){
|
||||
switch (v.getId()){
|
||||
case R.id.ivLeft:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
65
app/src/main/java/com/king/zxing/app/QRCodeScanActivity.java
Normal file
65
app/src/main/java/com/king/zxing/app/QRCodeScanActivity.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package com.king.zxing.app;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.king.camera.scan.AnalyzeResult;
|
||||
import com.king.camera.scan.CameraScan;
|
||||
import com.king.camera.scan.analyze.Analyzer;
|
||||
import com.king.zxing.DecodeConfig;
|
||||
import com.king.zxing.DecodeFormatManager;
|
||||
import com.king.zxing.BarcodeCameraScanActivity;
|
||||
import com.king.zxing.analyze.QRCodeAnalyzer;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* 扫二维码识别示例
|
||||
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
public class QRCodeScanActivity extends BarcodeCameraScanActivity {
|
||||
|
||||
@Override
|
||||
public void initCameraScan(@NonNull CameraScan<Result> cameraScan) {
|
||||
super.initCameraScan(cameraScan);
|
||||
// 根据需要设置CameraScan相关配置
|
||||
cameraScan.setPlayBeep(true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Analyzer<Result> createAnalyzer() {
|
||||
//初始化解码配置
|
||||
DecodeConfig decodeConfig = new DecodeConfig();
|
||||
decodeConfig.setHints(DecodeFormatManager.QR_CODE_HINTS)//如果只有识别二维码的需求,这样设置效率会更高,不设置默认为DecodeFormatManager.DEFAULT_HINTS
|
||||
.setFullAreaScan(false)//设置是否全区域识别,默认false
|
||||
.setAreaRectRatio(0.8f)//设置识别区域比例,默认0.8,设置的比例最终会在预览区域裁剪基于此比例的一个矩形进行扫码识别
|
||||
.setAreaRectVerticalOffset(0)//设置识别区域垂直方向偏移量,默认为0,为0表示居中,可以为负数
|
||||
.setAreaRectHorizontalOffset(0);//设置识别区域水平方向偏移量,默认为0,为0表示居中,可以为负数
|
||||
// BarcodeCameraScanActivity默认使用的MultiFormatAnalyzer,这里可以改为使用QRCodeAnalyzer
|
||||
return new QRCodeAnalyzer(decodeConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局ID;通过覆写此方法可以自定义布局
|
||||
*
|
||||
* @return 布局ID
|
||||
*/
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_qrcode_scan;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanResultCallback(@NonNull AnalyzeResult<Result> result) {
|
||||
// 停止分析
|
||||
getCameraScan().setAnalyzeImage(false);
|
||||
// 返回结果
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(CameraScan.SCAN_RESULT, result.getResult().getText());
|
||||
setResult(Activity.RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Jenly Yu
|
||||
*
|
||||
* 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.zxing.app.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.king.zxing.app.R;
|
||||
|
||||
import androidx.annotation.FloatRange;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
/**
|
||||
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
public final class StatusBarUtils {
|
||||
|
||||
private StatusBarUtils(){
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static void immersiveStatusBar(Activity activity, Toolbar toolbar) {
|
||||
immersiveStatusBar(activity,toolbar,0.0f);
|
||||
}
|
||||
|
||||
public static void immersiveStatusBar(Activity activity,Toolbar toolbar,@FloatRange(from = 0.0, to = 1.0) float alpha) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
return;
|
||||
}
|
||||
|
||||
Window window = activity.getWindow();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
window.setStatusBarColor(Color.TRANSPARENT);
|
||||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
||||
} else {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
}
|
||||
|
||||
ViewGroup decorView = (ViewGroup) window.getDecorView();
|
||||
ViewGroup contentView = window.getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
|
||||
View rootView = contentView.getChildAt(0);
|
||||
if (rootView != null) {
|
||||
rootView.setFitsSystemWindows(false);
|
||||
}
|
||||
if(toolbar!=null){
|
||||
toolbar.setPadding(0,getStatusBarHeight(activity),0,0);
|
||||
}
|
||||
|
||||
decorView.addView(createStatusBarView(activity,alpha));
|
||||
}
|
||||
|
||||
private static View createStatusBarView(Activity activity,@FloatRange(from = 0.0, to = 1.0) float alpha) {
|
||||
// 绘制一个和状态栏一样高的矩形
|
||||
View statusBarView = new View(activity);
|
||||
LinearLayout.LayoutParams params =
|
||||
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
|
||||
statusBarView.setLayoutParams(params);
|
||||
statusBarView.setBackgroundColor(Color.argb((int) (alpha * 255), 0, 0, 0));
|
||||
statusBarView.setId(R.id.translucent_view);
|
||||
return statusBarView;
|
||||
}
|
||||
|
||||
/** 获取状态栏高度 */
|
||||
public static int getStatusBarHeight(Context context) {
|
||||
return context.getResources().getDimensionPixelSize(R.dimen.status_bar_height);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package com.king.zxing.app.util;
|
||||
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
|
||||
import com.king.zxing.util.LogUtils;
|
||||
|
||||
/**
|
||||
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
public final class UriUtils {
|
||||
|
||||
private UriUtils(){
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片
|
||||
*/
|
||||
public static String getImagePath(Context context,Intent data) {
|
||||
String imagePath = null;
|
||||
Uri uri = data.getData();
|
||||
//获取系統版本
|
||||
int currentapiVersion = Build.VERSION.SDK_INT;
|
||||
if(currentapiVersion> Build.VERSION_CODES.KITKAT){
|
||||
LogUtils.d("uri=intent.getData :" + uri);
|
||||
if (DocumentsContract.isDocumentUri(context, uri)) {
|
||||
String docId = DocumentsContract.getDocumentId(uri);
|
||||
Log.d("getDocumentId(uri) :", "" + docId);
|
||||
Log.d("uri.getAuthority() :", "" + uri.getAuthority());
|
||||
if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
|
||||
String id = docId.split(":")[1];
|
||||
String selection = MediaStore.Images.Media._ID + "=" + id;
|
||||
imagePath = getImagePath(context,MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);
|
||||
} else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
|
||||
Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId));
|
||||
imagePath = getImagePath(context,contentUri, null);
|
||||
}
|
||||
|
||||
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
||||
imagePath = getImagePath(context,uri, null);
|
||||
}
|
||||
}else{
|
||||
imagePath = getImagePath(context,uri, null);
|
||||
}
|
||||
|
||||
return imagePath;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过uri和selection来获取真实的图片路径,从相册获取图片时要用
|
||||
*/
|
||||
private static String getImagePath(Context context,Uri uri, String selection) {
|
||||
String path = null;
|
||||
Cursor cursor = context.getContentResolver().query(uri, null, selection, null, null);
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.5 KiB |
@@ -26,122 +26,84 @@
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:text="@string/app_name"/>
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn0"
|
||||
android:id="@+id/btnMultiFormat"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:text="默认扫码"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="连续扫码(识别多种格式)"
|
||||
app:layout_constraintTop_toBottomOf="@+id/toolbar"
|
||||
style="@style/OnClick"/>
|
||||
<Button
|
||||
android:id="@+id/btn1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:text="连续扫码"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btn0"
|
||||
style="@style/OnClick"/>
|
||||
<Button
|
||||
android:id="@+id/btn2"
|
||||
android:id="@+id/btnQRCode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:text="Fragment扫码"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="扫二维码"
|
||||
android:textAllCaps="false"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btn1"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btnMultiFormat"
|
||||
style="@style/OnClick"/>
|
||||
<Button
|
||||
android:id="@+id/btn3"
|
||||
android:id="@+id/btnFullQRCode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:text="自定义布局扫码"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="扫二维码(全屏识别)"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btn2"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btnQRCode"
|
||||
style="@style/OnClick"/>
|
||||
<Button
|
||||
android:id="@+id/btn4"
|
||||
android:id="@+id/btnPickPhoto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:text="自定义全屏扫二维码"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="选择图片识别"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btn3"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btnFullQRCode"
|
||||
style="@style/OnClick"/>
|
||||
<Button
|
||||
android:id="@+id/btn5"
|
||||
android:id="@+id/btnGenerateQrCode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:text="生成条形码"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btn4"
|
||||
style="@style/OnClick"/>
|
||||
<Button
|
||||
android:id="@+id/btn6"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="生成二维码"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btn5"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btnPickPhoto"
|
||||
style="@style/OnClick"/>
|
||||
<Button
|
||||
android:id="@+id/btn7"
|
||||
android:id="@+id/btnGenerateBarcode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:text="识别一维码/二维码图片"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="生成线性条形码"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btn6"
|
||||
style="@style/OnClick"/>
|
||||
<Button
|
||||
android:id="@+id/btn8"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:text="只识别二维码"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btn7"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btnGenerateQrCode"
|
||||
style="@style/OnClick"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
28
app/src/main/res/layout/activity_qrcode_scan.xml
Normal file
28
app/src/main/res/layout/activity_qrcode_scan.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<androidx.camera.view.PreviewView
|
||||
android:id="@+id/previewView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<com.king.view.viewfinderview.ViewfinderView
|
||||
android:id="@+id/viewfinderView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:vvLaserStyle="grid"
|
||||
app:vvLabelTextLocation="bottom"
|
||||
app:vvLabelText="@string/tips_scan_qr_code"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivFlashlight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="@dimen/camera_scan_flashlight_margin_top"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/camera_scan_flashlight_selector" />
|
||||
</FrameLayout>
|
||||
@@ -6,6 +6,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<include android:id="@+id/toolbar"
|
||||
layout="@layout/toolbar"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivCode"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -15,4 +16,13 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/toolbar"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvBarcodeFormat"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@+id/ivCode"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:gravity="center_horizontal"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.camera.view.PreviewView
|
||||
android:id="@+id/previewView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
<com.king.zxing.ViewfinderView
|
||||
android:id="@+id/viewfinderView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:viewfinderStyle="popular"
|
||||
app:laserStyle="image"
|
||||
app:laserDrawableRatio="0.8"
|
||||
app:laserDrawable="@drawable/ic_laser_line"/>
|
||||
<ImageView
|
||||
android:id="@+id/ivFlash"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/zxl_flashlight_selector"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginTop="170dp" />
|
||||
<include layout="@layout/toolbar_capture"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.camera.view.PreviewView
|
||||
android:id="@+id/previewView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
<com.king.zxing.ViewfinderView
|
||||
android:id="@+id/viewfinderView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:labelText="@string/tips_scan_code"
|
||||
app:labelTextSize="@dimen/size_14sp"
|
||||
app:laserColor="@color/colorAccent"
|
||||
app:frameColor="@color/colorPrimary"
|
||||
app:cornerColor="@color/colorPrimary"
|
||||
app:labelTextLocation="bottom"
|
||||
app:laserStyle="grid" />
|
||||
<ImageView
|
||||
android:id="@+id/ivFlashlight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/zxl_flashlight_selector"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginTop="170dp" />
|
||||
<include layout="@layout/toolbar_capture"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<include layout="@layout/zxl_capture"/>
|
||||
<include layout="@layout/toolbar_capture"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:id="@+id/fragmentContent"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
<include layout="@layout/toolbar_capture"/>
|
||||
</FrameLayout>
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.camera.view.PreviewView
|
||||
android:id="@+id/previewView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
<com.king.zxing.ViewfinderView
|
||||
android:id="@+id/viewfinderView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:labelText="@string/tips_scan_code"
|
||||
app:labelTextSize="@dimen/size_14sp"
|
||||
app:laserColor="@color/colorAccent"
|
||||
app:frameColor="@color/colorPrimary"
|
||||
app:cornerColor="@color/colorPrimary"
|
||||
app:labelTextLocation="bottom"
|
||||
app:laserStyle="grid" />
|
||||
<ImageView
|
||||
android:id="@+id/ivFlashlight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/zxl_flashlight_selector"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginTop="170dp" />
|
||||
<include layout="@layout/toolbar_capture"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<item name="statusbar_view" type="id"/>
|
||||
<item name="translucent_view" type="id"/>
|
||||
</resources>
|
||||
@@ -1,8 +1,5 @@
|
||||
<resources>
|
||||
<string name="app_name">ZXingLite</string>
|
||||
<string name="permission_camera">App扫码需要用到拍摄权限</string>
|
||||
<string name="permission_external_storage">App需要用到读写权限</string>
|
||||
<string name="tips_scan_code">将二维码/条形码放入框内,即可自动扫描</string>
|
||||
<string name="qr_code">二维码</string>
|
||||
<string name="bar_code">条形码</string>
|
||||
<string name="tips_scan_qr_code">将二维码放入框内,即可自动扫描</string>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user