首页 > 学院 > 开发设计 > 正文

Google ZXing系列讲解(三)——ZXing 目录结构与主体流程

2019-11-07 23:13:55
字体:
来源:转载
供稿:网友

概要

本篇讲解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类关系图

Capture类关系图

camera包结构

camera包结构

该package作用是管理camera,包括打开,关闭,配置camere, 闪光灯等。 - CameraFacing: 枚举类, 标明前置摄像头,后置摄像头 - OpenCamera: 表示已经打开的Camera以及它的元数据 - OpenCameraInterface :抽象于Camera之上的类,用于打开Camera并获得数据 - AutoFocusManager:Camera自动对焦相关 - CameraConfigurationManager:用于读取,分析,设置Camera参数 - CameraManager: 核心类,相机管理类, 操作Camera的入口,用于预览和解码 - FrontLightMode:枚举类, 表示闪光灯的开,关,自动 - PreviewCallback:预览回调类

ZXing Camera具体流程

ZXing Camera打开流程

以上流程图,经过手机 log调试,内容属实! 该图展示,ZXing 打开Camera 扫描 1D/2D 主体流程。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表