Google ZXing系列讲解(三)——ZXing 目录结构与主体流程
2017-02-26 10:21
429 查看
概要
本篇讲解2个问题- ZXing Demo结构
- ZXing Demo 主体流程
ZXing 结构
本系列涉及的都是Google ZXing Demo, 也就是源码中的android目录。从 Google ZXing系列讲解(一)——导入AS 就提到 ZXing源码中的目录分类,包含内容较多。从Android实际使用角度,会涉及
core,
android-core,
android-integration,
android四个目录。
-
core可以认为是ZXing库的核心算法,
-
android-core中仅有一个文件
CameraConfigurationUtils.java, 该文件的说明是:
/** * Utility methods for configuring the Android camera. * * @author Sean Owen */
android-integration仅有2个文件
IntentIntegrator.java <p>A utility class which helps ease integration with Barcode Scanner via {@link Intent}s. This is a simple way to invoke barcode scanning and receive the result, without any need to integrate, modify, or learn the project's source code.</p>
IntentResult.java <p>Encapsulates the result of a barcode scan invoked through {@link IntentIntegrator}.</p>
该jar包用于第三方应用通过Intent调用ZXing app。
-
android
ZXing Demo, 用于展示如何使用ZXing库。
该系列文章以
android目录为研究对象, 分析如何使用ZXing。
ZXing Demo目录结构
该Demo实现的功能很多, 扫描条形码,二维码。扫描书籍, 剪切板, 编码, 扫描历史记录,分享,扫描WIFI。
- book: 扫描结果是书籍信息,则进行相关操作,包括搜索与展示书籍相关类。
- camera: Camera相关操作包, open/ 是Camera打开相关类,CameraManager是核心管理类。
- clipboard: 剪贴板
- encode:编码功能的各个组件集合,核心类为QRCodeEncoder
- history:扫描历史管理,核心类是HistoryManager
- result: 扫码结果被分为不同的类型,所有的类型,都定义对应的xxxResultHandler来处理。
- share: 将扫码结果分享出去
- wifi: 扫码自动连接WIFI
ZXing Android 摄像头启动过程
在介绍ZXing Android Camera启动过程前 ,先来看下扫码总体流程ZXing扫码整体过程
ZXing Android入口
带UI界面的Android App都有一个入口Activity, 从AndroidManifest.xml中可以查验
<activity android:name=".CaptureActivity" ......> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> ... ... </activity>
所以,类
CaptureActivity就是ZXing Demo的入口Activity, 仔细查看其生命周期函数,发现做了很多工作。
onCreate
inactivityTimer = new InactivityTimer(this); beepManager = new BeepManager(this); ambientLightManager = new AmbientLightManager(this);
创建一个Timer:如果设备使用电池供电,一段时间不活动之后结束activity
创建一个BeepManager:主要用于扫描成功后提示声的
设置保持屏幕唤醒状态
onResume
初始化Camera:使用CameraManager,这个类主要提供关于Camera的一些基本操作初始化ViewfinderView:覆盖在预览图(SurfaceView)上方的一个View,主要作用是增加了部分透明的取景框和扫描动画;我们可以根据需要改变取景框的大小形状,改变扫描动画等。
初始化SurfaceView
CaptureActivity类关系图
camera包结构
该package作用是管理camera,包括打开,关闭,配置camere, 闪光灯等。
- CameraFacing: 枚举类, 标明前置摄像头,后置摄像头
- OpenCamera: 表示已经打开的Camera以及它的元数据
- OpenCameraInterface :抽象于Camera之上的类,用于打开Camera并获得数据
- AutoFocusManager:Camera自动对焦相关
- CameraConfigurationManager:用于读取,分析,设置Camera参数
- CameraManager: 核心类,相机管理类, 操作Camera的入口,用于预览和解码
- FrontLightMode:枚举类, 表示闪光灯的开,关,自动
- PreviewCallback:预览回调类
ZXing Camera具体流程
以上流程图,经过手机 log调试,内容属实! 该图展示,ZXing 打开Camera 扫描 1D/2D 主体流程。
相关文章推荐
- Google ZXing系列讲解(四)——ZXing 解决竖屏扫描问题
- Google ZXing系列讲解(五)——ZXing 仿微信扫描UI
- ruby on rails 入门系列--rails目录结构简述
- codeigniter框架目录结构及远行流程
- jdk1.6结构 目录讲解
- Mozilla系列——Mozilla目录结构剖析
- sencha touch 入门系列 (四)sencha touch 新建项目目录结构解析
- 深入Atlas系列:客户端网络访问基础结构(上) - WebRequest的工作流程与生命周期
- iOS项目的目录结构和开发流程
- iOS/iPhone 程序文件目录结构以及启动流程
- 《android学习总结笔记》系列--android 目录结构
- Android系列教程之四:Android项目的目录结构
- ruby on rails 入门系列--rails目录结构简述
- iOS/iPhone 程序文件目录结构以及启动流程
- 【Cocoa(mac) Application 开发系列之四】动作编辑器(Cocos2dx)制作流程详解及附上响应鼠标滚轴事件、反转坐标系、导入/创建资源目录等知识点代码!
- RHEL6入门系列之四,磁盘分区、文件系统和目录结构
- Linux系统的目录结构--Linux入门到精通系列
- 位运算讲解系列文章(目录)
- RHEL6入门系列之四,磁盘分区、文件系统和目录结构
- codeigniter框架目录结构、运行流程