/*
* Copyright (C) 2008 ZXing authors
*
* 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.google.zxing.client.android;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
import com.google.zxing.Result;
import com.google.zxing.ResultMetadataType;
import com.google.zxing.ResultPoint;
import com.google.zxing.client.android.camera.CameraManager;
import com.google.zxing.client.android.common.CaptureActivityHandler;
import com.google.zxing.client.android.common.FinishListener;
import com.google.zxing.client.android.common.ViewfinderView;
import com.google.zxing.client.android.common.InactivityTimer;
import com.google.zxing.client.android.common.AmbientLightManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.EnumSet;
import java.util.Map;
/**
* This activity opens the camera and does the actual scanning on a background thread. It draws a
* viewfinder to help the user place the barcode correctly, shows feedback as the image processing
* is happening, and then overlays the results when a scan is successful.
*
* @author dswitkin@google.com (Daniel Switkin)
* @author Sean Owen
*/
public final class CaptureActivity extends Activity implements SurfaceHolder.Callback {
private static final String TAG = CaptureActivity.class.getSimpleName();
public static final boolean IS_PORTRAIT = true;//是否为竖屏
private static final Collection<ResultMetadataType> DISPLAYABLE_METADATA_TYPES =
EnumSet.of(ResultMetadataType.ISSUE_NUMBER,
ResultMetadataType.SUGGESTED_PRICE,
ResultMetadataType.ERROR_CORRECTION_LEVEL,
ResultMetadataType.POSSIBLE_COUNTRY);
private CameraManager cameraManager;
private CaptureActivityHandler handler;
private Result savedResultToShow;
private ViewfinderView viewfinderView;
private TextView statusView;
private View resultView;
private Result lastResult;
private boolean hasSurface;
private Collection<BarcodeFormat> decodeFormats;
private Map<DecodeHintType,?> decodeHints;
private String characterSet;
private InactivityTimer inactivityTimer;
private AmbientLightManager ambientLightManager;
public ViewfinderView getViewfinderView() {
return viewfinderView;
}
public Handler getHandler() {
return handler;
}
public CameraManager getCameraManager() {
return cameraManager;
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.capture);
hasSurface = false;
inactivityTimer = new InactivityTimer(this);
ambientLightManager = new AmbientLightManager(this);
}
@Override
protected void onResume() {
super.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.
cameraManager = new CameraManager(getApplication());
viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
viewfinderView.setCameraManager(cameraManager);
resultView = findViewById(R.id.result_view);
statusView = (TextView) findViewById(R.id.status_view);
handler = null;
lastResult = null;
if(IS_PORTRAIT){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}
resetStatusView();
ambientLightManager.start(cameraManager);
inactivityTimer.onResume();
decodeFormats = null;
characterSet = null;
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
if (hasSurface) {
// The activity was paused but not stopped, so the surface still exists. Therefore
// surfaceCreated() won't be called, so init the camera here.
initCamera(surfaceHolder);
} else {
// Install the callback and wait for surfaceCreated() to init the camera.
surfaceHolder.addCallback(this);
}
}
@Override
protected void onPause() {
if (handler != null) {
handler.quitSynchronously();
handler = null;
}
inactivityTimer.onPause();
ambientLightManager.stop();
cameraManager.closeDriver();
//historyManager = null; // Keep for onActivityResult
if (!hasSurface) {
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
surfaceHolder.removeCallback(this);
}
super.onPause();
}
@Override
protected void onDestroy() {
inactivityTimer.shutdown();
super.onDestroy();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (lastResult != null) {
restartPreviewAfterDelay(0L);
return true;
}
break;
case KeyEvent.KEYCODE_FOCUS:
case KeyEvent.KEYCODE_CAMERA:
// Handle these events so they don't launch the Camera app
return true;
// Use volume up/down to turn on light
case KeyEvent.KEYCODE_VOLUME_DOWN:
cameraManager.setTorch(false);
return true;
case KeyEvent.KEYCODE_VOLUME_UP:
cameraManager.setTorch(true);
return true;
}
return super.onKeyDown(keyCode, event);
}
private void decodeOrStoreSavedBitmap(Bitmap bitmap, Result result) {
// Bitmap isn't used yet -- will be used soon
if (handler == null) {
savedResultToShow = result;
} else {
if (result != null) {
savedResultToShow = result;
}
if (savedResultToShow != null) {
Message message = Message.obtain(handler, R.id.decode_succeeded, savedResultToShow);
handler.sendMessage(message);
}
savedResultToShow = null;
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (holder == null) {
Log.e(TAG, "*** WARNING *** surfaceCreated() gave us a null surface!");
}
if (!hasSurface) {
hasSurface = true;
initCamera(holder);
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
hasSurface = false;
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
/**
* A valid barcode has been found, so give an indication of success and show the results.
*
* @param rawResult The contents of the barcode.
* @param scaleFactor amount by
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Zxing最新demo【精简支持横竖屏】.zip (79个子文件)
ZxingDemo
ZxingDemo.iml 915B
gradlew 5KB
settings.gradle 16B
.DS_Store 8KB
.idea
libraries
android_core_3_2_0.xml 529B
appcompat_v7_21_0_3.xml 417B
core_3_2_0.xml 308B
support_v4_21_0_3.xml 727B
support_annotations_21_0_3.xml 515B
.DS_Store 6KB
misc.xml 973B
compiler.xml 686B
workspace.xml 106KB
gradle.xml 667B
.name 9B
modules.xml 355B
copyright
profiles_settings.xml 74B
vcs.xml 164B
gradle
.DS_Store 6KB
wrapper
gradle-wrapper.properties 232B
gradle-wrapper.jar 49KB
.gradle
2.2.1
taskArtifacts
cache.properties.lock 17B
fileHashes.bin 219KB
outputFileStates.bin 20KB
taskArtifacts.bin 92KB
fileSnapshots.bin 2.45MB
cache.properties 31B
local.properties 460B
gradlew.bat 2KB
gradle.properties 872B
.gitignore 98B
app
.DS_Store 6KB
src
.DS_Store 6KB
androidTest
java
com
example
qiudongchao
zxingdemo
ApplicationTest.java 376B
main
.DS_Store 6KB
AndroidManifest.xml 5KB
res
values-zh-rHK 13B
values-zh-rCN
strings.xml 9KB
drawable-hdpi
launcher_icon.png 4KB
drawable
launcher_icon.png 2KB
layout
capture.xml 7KB
drawable-xxhdpi
launcher_icon.png 13KB
drawable-xhdpi
launcher_icon.png 9KB
values
colors.xml 1KB
ids.xml 931B
arrays.xml 2KB
themes.xml 946B
strings.xml 9KB
styles.xml 1KB
dimens.xml 730B
values-iw 10B
java
.DS_Store 6KB
com
.DS_Store 6KB
google
.DS_Store 6KB
zxing
.DS_Store 6KB
client
.DS_Store 6KB
android
common
FinishListener.java 1KB
ViewfinderView.java 7KB
DecodeHandler.java 4KB
InactivityTimer.java 3KB
DecodeFormatManager.java 2KB
DecodeThread.java 3KB
AmbientLightManager.java 3KB
CaptureActivityHandler.java 6KB
ViewfinderResultPointCallback.java 1KB
.DS_Store 6KB
camera
.DS_Store 6KB
PreviewCallback.java 2KB
open
OpenCameraInterface.java 2KB
CameraConfigurationManager.java 5KB
AutoFocusManager.java 4KB
CameraManager.java 11KB
FrontLightMode.java 1KB
CaptureActivity.java 14KB
libs
app.iml 8KB
.gitignore 8B
build.gradle 717B
proguard-rules.pro 706B
build.gradle 455B
共 79 条
- 1
资源评论
kuwu2000
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- auto-ohos-default-HotStartAbilityTest-com.hits.hotstartabilityre
- h5项目中 在钉钉分享时 分享卡片icon图标如何设置
- 知识领域: 网络安全 技术关键词: 漏洞分析、渗透测试、加密算法 内容关键词: 攻击防范、身份验证、网络流量分析
- 蜂网-SCM商品成本核算.pptx
- 知识领域: DevOps 技术关键词: 自动化、持续集成、容器化 内容关键词: 部署流程、监控与日志、云计算
- gerenzishuA
- 计算机Linux操作系统远程连接
- delphi人才信息管理系统.zip
- 知识领域: 嵌入式系统开发 技术关键词: C、C++、RTOS、嵌入式硬件 内容关键词: 实时系统、低功耗设计、传感器接口
- 电子科技大学 计算机操作系统知识介绍、实验源代码及实验报告
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功