package com.cqc.zxing01.zxing;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import com.cqc.zxing01.R;
import com.cqc.zxing01.zxing.camera.CameraManager;
import com.cqc.zxing01.zxing.decode.DecodeThread;
import com.cqc.zxing01.zxing.decode.PhotoScanHandler;
import com.cqc.zxing01.zxing.decode.RGBLuminanceSource;
import com.cqc.zxing01.zxing.utils.BeepManager;
import com.cqc.zxing01.zxing.utils.BitmapUtil;
import com.cqc.zxing01.zxing.utils.CaptureActivityHandler;
import com.cqc.zxing01.zxing.utils.InactivityTimer;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Result;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Map;
public class ScanManager implements SurfaceHolder.Callback {
boolean isHasSurface = false;
CameraManager cameraManager;
//用于拍摄扫描的handler
CaptureActivityHandler handler;
//用于照片扫描的handler,不可共用,图片扫描是不需要摄像机的
PhotoScanHandler photoScanHandler;
Rect mCropRect = null;
InactivityTimer inactivityTimer;
public BeepManager beepManager;
SurfaceView scanPreview = null;
View scanContainer;
View scanCropView;
ImageView scanLine;
final String TAG = ScanManager.class.getSimpleName();
Activity activity;
ScanListener listener;
boolean isOpenLight = false;
private int scanMode;//扫描模型(条形,二维码,全部)
/**
* 用于启动照相机扫描二维码,在activity的onCreate里面构造出来
* 在activity的生命周期中调用此类相对应的生命周期方法
*
* @param activity 扫描的activity
* @param scanPreview 预览的SurfaceView
* @param scanContainer 扫描的布局,全屏布局
* @param scanCropView 扫描的矩形区域
* @param scanLine 扫描线
*/
public ScanManager(Activity activity, SurfaceView scanPreview, View scanContainer,
View scanCropView, ImageView scanLine, int scanMode, ScanListener listener) {
this.activity = activity;
this.scanPreview = scanPreview;
this.scanContainer = scanContainer;
this.scanCropView = scanCropView;
this.scanLine = scanLine;
this.listener = listener;
this.scanMode = scanMode;
//启动动画
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
0.9f);
animation.setDuration(4500);
animation.setRepeatCount(-1);
animation.setRepeatMode(Animation.RESTART);
scanLine.startAnimation(animation);
}
/**
* 用于图片扫描的构造函数
*
* @param listener 结果的监听回调
*/
public ScanManager(ScanListener listener) {
this.listener = listener;
}
public void onResume() {
// CameraManager must be initialized here, not in onCreate(). This is
// necessary because we don't
// want to open the camera driver and measure the screen size if we're
// going to show the help on
// first launch. That led to bugs where the scanning rectangle was the
// wrong size and partially
// off screen.
inactivityTimer = new InactivityTimer(activity);
beepManager = new BeepManager(activity);
cameraManager = new CameraManager(activity.getApplicationContext());
handler = null;
if (isHasSurface) {
// The activity was paused but not stopped, so the surface still
// exists. Therefore
// surfaceCreated() won't be called, so init the camera here.
initCamera(scanPreview.getHolder());
} else {
// Install the callback and wait for surfaceCreated() to init the
// camera.
scanPreview.getHolder().addCallback(this);
}
inactivityTimer.onResume();
}
public void onPause() {
if (handler != null) {
handler.quitSynchronously();
handler = null;
}
inactivityTimer.onPause();
beepManager.close();
cameraManager.closeDriver();
if (!isHasSurface) {
scanPreview.getHolder().removeCallback(this);
}
}
public void onDestroy() {
inactivityTimer.shutdown();
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (holder == null) {
Log.e(TAG, "*** WARNING *** surfaceCreated() gave us a null surface!");
}
if (!isHasSurface) {
isHasSurface = true;
initCamera(holder);
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
isHasSurface = false;
}
void initCamera(SurfaceHolder surfaceHolder) {
if (surfaceHolder == null) {
throw new IllegalStateException("No SurfaceHolder provided");
}
if (cameraManager.isOpen()) {
Log.w(TAG, "initCamera() while already open -- late SurfaceView callback?");
return;
}
try {
cameraManager.openDriver(surfaceHolder);
// Creating the handler starts the preview, which can also throw a
// RuntimeException.
if (handler == null) {
handler = new CaptureActivityHandler(this, cameraManager, scanMode);
Log.e("hongliang1", "handler new成功!:" + handler);
}
initCrop();
} catch (IOException ioe) {
Log.e(TAG, "hongliang", ioe);
//弹出提示,报错
ioe.printStackTrace();
listener.scanError(new Exception("相机打开出错,请检查是否被禁止了该权限!"));
} catch (RuntimeException e) {
Log.e(TAG, "hongliang", e);
//弹出提示,报错
e.printStackTrace();
listener.scanError(new Exception("相机打开出错,请检查是否被禁止了该权限!"));
}
}
/**
* 开关闪关灯
*/
public void switchLight() {
if (isOpenLight) {
cameraManager.offLight();
} else {
cameraManager.openLight();
}
isOpenLight = !isOpenLight;
}
public Handler getHandler() {
return handler;
}
public CameraManager getCameraManager() {
return cameraManager;
}
public Rect getCropRect() {
return mCropRect;
}
/**
* 扫描成功的结果回调
*
* @param rawResult
* @param bundle
*/
public void handleDecode(Result rawResult, Bundle bundle) {
inactivityTimer.onActivity();
//扫描成功播放声音滴一下,可根据需要自行确定什么时候播
beepManager.playBeepSoundAndVibrate();
bundle.putInt("width", mCropRect.width());
bundle.putInt("height", mCropRect.height());
bundle.putString("result", rawResult.getText());
listener.scanResult(rawResult, bundle);
}
public void handleDecodeError(Exception e) {
listener.scanError(e);
}
/**
* 初始化截取的矩形区域
*/
没有合适的资源?快使用搜索试试~ 我知道了~
Zxing二维码一维码扫描生成Android源码
共71个文件
java:29个
xml:16个
png:13个
需积分: 15 23 下载量 180 浏览量
2018-01-17
09:30:52
上传
评论
收藏 1.06MB ZIP 举报
温馨提示
支持一维码,二维码,扫描生成。源码为studio工程,直接导入即可运行,有问题联系作者
资源推荐
资源详情
资源评论
收起资源包目录
zxing01-master.zip (71个子文件)
zxing01
gradlew.bat 2KB
gradlew 5KB
gradle.properties 730B
app
proguard-rules.pro 924B
src
test
java
com
cqc
zxing01
ExampleUnitTest.java 393B
androidTest
java
com
cqc
zxing01
ExampleInstrumentedTest.java 734B
main
res
raw
beep.ogg 6KB
mipmap-xxxhdpi
ic_launcher.png 10KB
ic_launcher_round.png 14KB
mipmap-hdpi
ic_launcher.png 3KB
ic_launcher_round.png 4KB
values
colors.xml 253B
Qrcode_ids.xml 936B
strings.xml 166B
styles.xml 381B
mipmap-xxhdpi
ic_launcher.png 8KB
ic_launcher_round.png 10KB
mipmap-mdpi
ic_launcher.png 2KB
ic_launcher_round.png 2KB
mipmap-xhdpi
ic_launcher.png 5KB
scanning_line.png 1KB
icon_light.png 4KB
icon_arrow.png 228B
ic_launcher_round.png 6KB
layout
activity_create_qr_code.xml 1KB
activity_main.xml 2KB
activity_scan_bar_code.xml 5KB
activity_create_bar_code.xml 1KB
java
com
cqc
zxing01
CreateQrCodeActivity.java 2KB
ScanQrCodeActivity.java 3KB
defineview
MyImageView.java 2KB
zxing
ScanListener.java 489B
camera
CameraManager.java 6KB
open
OpenCameraInterface.java 2KB
AutoFocusManager.java 4KB
CameraConfigurationManager.java 7KB
PreviewCallback.java 2KB
decode
RGBLuminanceSource.java 3KB
PhotoScanHandler.java 789B
DecodeHandler.java 5KB
DecodeThread.java 3KB
Utils.java 6KB
DecodeFormatManager.java 2KB
encode
EncodingHandler.java 3KB
ScanManager.java 12KB
utils
BitmapUtil.java 2KB
BeepManager.java 4KB
InactivityTimer.java 3KB
AppliationUtil.java 516B
CaptureActivityHandler.java 3KB
MainActivity.java 3KB
ToastUtil.java 541B
ScanAllCodeActivity.java 3KB
ScanBarCodeActivity.java 3KB
CreateBarCodeActivity.java 2KB
AndroidManifest.xml 2KB
.gitignore 7B
build.gradle 1016B
libs
zxing.jar 977KB
gradle
wrapper
gradle-wrapper.jar 52KB
gradle-wrapper.properties 230B
.idea
gradle.xml 626B
runConfigurations.xml 564B
misc.xml 2KB
copyright
profiles_settings.xml 74B
modules.xml 351B
encodings.xml 159B
compiler.xml 686B
.gitignore 118B
settings.gradle 15B
build.gradle 498B
共 71 条
- 1
资源评论
jasonleeningning
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- mmqrcode1714153659780.png
- Screenshot_2024-04-27-06-08-58-486_com.baidu.xin.aiqicha.jpg
- 基于Javaweb+Tomcat+MySQL的大学生公寓管理系统+sql文件.zip
- 实训作业基于javaweb的订单管理系统源码+数据库+实训报告.zip
- 多机调度问题贪心算法基于最小堆和贪心算法求解多机调度问题.zip
- 基于同态加密技术的匿名电子投票系统源码.zip
- Pyqt5项目框架-PyQt项目开发实践
- 基于C通过MQTT的智能农业大棚管理系统(本科毕业设计)
- python+CNN的网络入侵检测算法源码.zip
- js 实现记住密码功能 js.cookie.min.js
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功