lib -> zxing-lite
This commit is contained in:
@@ -50,5 +50,5 @@ dependencies {
|
|||||||
|
|
||||||
implementation deps.easypermissions
|
implementation deps.easypermissions
|
||||||
|
|
||||||
implementation project(':lib')
|
implementation project(':zxing-lite')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,21 +18,20 @@ package com.king.zxing.app;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.king.zxing.CameraScan;
|
import com.king.zxing.CameraScan;
|
||||||
import com.king.zxing.CaptureActivity;
|
import com.king.zxing.CaptureActivity;
|
||||||
import com.king.zxing.app.util.UriUtils;
|
|
||||||
import com.king.zxing.util.CodeUtils;
|
import com.king.zxing.util.CodeUtils;
|
||||||
import com.king.zxing.util.LogUtils;
|
import com.king.zxing.util.LogUtils;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@@ -50,9 +49,9 @@ import pub.devrel.easypermissions.EasyPermissions;
|
|||||||
*
|
*
|
||||||
* 2、通过继承CaptureActivity或者CaptureFragment并自定义布局。(适用于大多场景,并无需关心扫码相关逻辑,自定义布局时需覆写getLayoutId方法)
|
* 2、通过继承CaptureActivity或者CaptureFragment并自定义布局。(适用于大多场景,并无需关心扫码相关逻辑,自定义布局时需覆写getLayoutId方法)
|
||||||
*
|
*
|
||||||
* 3、在你项目的Activity或者Fragment中创建一个CaptureHelper并在相应的生命周期中调用CaptureHelper的周期。(适用于想在扫码界面写交互逻辑,又因为项目架构或其它原因,无法直接或间接继承CaptureActivity或CaptureFragment时使用)
|
* 3、在你项目的Activity或者Fragment中实例化一个CameraScan即可。(适用于想在扫码界面写交互逻辑,又因为项目架构或其它原因,无法直接或间接继承CaptureActivity或CaptureFragment时使用)
|
||||||
*
|
*
|
||||||
* 4、参照CaptureHelper写一个自定义的扫码帮助类,其它步骤同方式3。(扩展高级用法,谨慎使用)
|
* 4、继承CameraScan自己实现一个,可参照默认实现类DefaultCameraScan,其它步骤同方式3。(扩展高级用法,谨慎使用)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks{
|
public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks{
|
||||||
@@ -109,26 +108,28 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void parsePhoto(Intent data){
|
private void parsePhoto(Intent data){
|
||||||
final String path = UriUtils.getImagePath(this,data);
|
|
||||||
LogUtils.d("path:" + path);
|
// final String path = UriUtils.getImagePath(this,data);
|
||||||
if(TextUtils.isEmpty(path)){
|
// LogUtils.d("path:" + path);
|
||||||
return;
|
// if(TextUtils.isEmpty(path)){
|
||||||
}
|
// return;
|
||||||
//异步解析
|
// }
|
||||||
asyncThread(new Runnable() {
|
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),data.getData());
|
||||||
final String result = CodeUtils.parseCode(path);
|
//异步解析
|
||||||
runOnUiThread(new Runnable() {
|
asyncThread(() -> {
|
||||||
@Override
|
final String result = CodeUtils.parseCode(bitmap);
|
||||||
public void run() {
|
runOnUiThread(() -> {
|
||||||
Log.d("Jenly","result:" + result);
|
LogUtils.d("result:" + result);
|
||||||
Toast.makeText(getContext(),result,Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(),result,Toast.LENGTH_SHORT).show();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import android.provider.DocumentsContract;
|
|||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.king.zxing.util.LogUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||||
*/
|
*/
|
||||||
@@ -28,7 +30,7 @@ public final class UriUtils {
|
|||||||
//获取系統版本
|
//获取系統版本
|
||||||
int currentapiVersion = Build.VERSION.SDK_INT;
|
int currentapiVersion = Build.VERSION.SDK_INT;
|
||||||
if(currentapiVersion> Build.VERSION_CODES.KITKAT){
|
if(currentapiVersion> Build.VERSION_CODES.KITKAT){
|
||||||
Log.d("uri=intent.getData :", "" + uri);
|
LogUtils.d("uri=intent.getData :" + uri);
|
||||||
if (DocumentsContract.isDocumentUri(context, uri)) {
|
if (DocumentsContract.isDocumentUri(context, uri)) {
|
||||||
String docId = DocumentsContract.getDocumentId(uri);
|
String docId = DocumentsContract.getDocumentId(uri);
|
||||||
Log.d("getDocumentId(uri) :", "" + docId);
|
Log.d("getDocumentId(uri) :", "" + docId);
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
include ':app', ':lib'
|
include ':app', ':zxing-lite'
|
||||||
|
|||||||
2
lib/.gitignore → zxing-lite/.gitignore
vendored
2
lib/.gitignore → zxing-lite/.gitignore
vendored
@@ -1 +1 @@
|
|||||||
/build
|
/build
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
apply plugin: 'com.novoda.bintray-release'
|
apply plugin: 'com.novoda.bintray-release'
|
||||||
|
|
||||||
//添加
|
//添加
|
||||||
publish {
|
publish {
|
||||||
userOrg = 'jenly'//bintray.com用户名
|
userOrg = 'jenly'//bintray.com用户名
|
||||||
groupId = 'com.king.zxing'//jcenter上的路径
|
groupId = 'com.king.zxing'//jcenter上的路径
|
||||||
artifactId = 'zxing-lite'//项目名称
|
artifactId = 'zxing-lite'//项目名称
|
||||||
publishVersion = app_version.versionName//版本号
|
publishVersion = app_version.versionName//版本号
|
||||||
desc = 'ZXingLite for Android'//描述
|
desc = 'ZXingLite for Android'//描述
|
||||||
website = 'https://github.com/jenly1314/ZXingLite'//网站
|
website = 'https://github.com/jenly1314/ZXingLite'//网站
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,51 +1,51 @@
|
|||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
apply from: 'bintray.gradle'
|
apply from: 'bintray.gradle'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion build_versions.compileSdk
|
compileSdkVersion build_versions.compileSdk
|
||||||
buildToolsVersion build_versions.buildTools
|
buildToolsVersion build_versions.buildTools
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion build_versions.minSdk
|
minSdkVersion build_versions.minSdk
|
||||||
targetSdkVersion build_versions.targetSdk
|
targetSdkVersion build_versions.targetSdk
|
||||||
versionCode app_version.versionCode
|
versionCode app_version.versionCode
|
||||||
versionName app_version.versionName
|
versionName app_version.versionName
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lintOptions {
|
lintOptions {
|
||||||
abortOnError false
|
abortOnError false
|
||||||
warning 'InvalidPackage'
|
warning 'InvalidPackage'
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//task javadoc(type: Javadoc) {
|
//task javadoc(type: Javadoc) {
|
||||||
// source = android.sourceSets.main.java.srcDirs
|
// source = android.sourceSets.main.java.srcDirs
|
||||||
// classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
|
// classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
|
||||||
//}
|
//}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
testImplementation deps.test.junit
|
testImplementation deps.test.junit
|
||||||
androidTestImplementation deps.test.runner
|
androidTestImplementation deps.test.runner
|
||||||
androidTestImplementation deps.test.espresso
|
androidTestImplementation deps.test.espresso
|
||||||
|
|
||||||
compileOnly deps.androidx.appcompat
|
compileOnly deps.androidx.appcompat
|
||||||
api deps.zxing
|
api deps.zxing
|
||||||
api deps.camera_core
|
api deps.camera_core
|
||||||
api deps.camera_camera2
|
api deps.camera_camera2
|
||||||
api deps.camera_lifecycle
|
api deps.camera_lifecycle
|
||||||
api deps.camera_view
|
api deps.camera_view
|
||||||
}
|
}
|
||||||
3
zxing-lite/gradle.properties
Normal file
3
zxing-lite/gradle.properties
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
POM_NAME=ZXingLite
|
||||||
|
POM_ARTIFACT_ID=zxing-lite
|
||||||
|
POM_PACKAGING=aar
|
||||||
@@ -1,34 +1,34 @@
|
|||||||
# Add project specific ProGuard rules here.
|
# Add project specific ProGuard rules here.
|
||||||
# You can control the set of applied configuration files using the
|
# You can control the set of applied configuration files using the
|
||||||
# proguardFiles setting in build.gradle.
|
# proguardFiles setting in build.gradle.
|
||||||
#
|
#
|
||||||
# For more details, see
|
# For more details, see
|
||||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
# If your project uses WebView with JS, uncomment the following
|
# If your project uses WebView with JS, uncomment the following
|
||||||
# and specify the fully qualified class name to the JavaScript interface
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
# class:
|
# class:
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
# public *;
|
# public *;
|
||||||
#}
|
#}
|
||||||
|
|
||||||
# Uncomment this to preserve the line number information for
|
# Uncomment this to preserve the line number information for
|
||||||
# debugging stack traces.
|
# debugging stack traces.
|
||||||
#-keepattributes SourceFile,LineNumberTable
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
# If you keep the line number information, uncomment this to
|
# If you keep the line number information, uncomment this to
|
||||||
# hide the original source file name.
|
# hide the original source file name.
|
||||||
#-renamesourcefileattribute SourceFile
|
#-renamesourcefileattribute SourceFile
|
||||||
|
|
||||||
#ZXingLite
|
#ZXingLite
|
||||||
-dontwarn com.king.zxing.**
|
-dontwarn com.king.zxing.**
|
||||||
-keep class com.king.zxing.**{ *;}
|
-keep class com.king.zxing.**{ *;}
|
||||||
-keepattributes InnerClasses
|
-keepattributes InnerClasses
|
||||||
-keepclassmembers enum * {
|
-keepclassmembers enum * {
|
||||||
public static **[] values();
|
public static **[] values();
|
||||||
public static ** valueOf(java.lang.String);
|
public static ** valueOf(java.lang.String);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ZXing
|
#ZXing
|
||||||
-dontwarn com.google.zxing.**
|
-dontwarn com.google.zxing.**
|
||||||
-keep class com.google.zxing.**{ *;}
|
-keep class com.google.zxing.**{ *;}
|
||||||
@@ -1,27 +1,27 @@
|
|||||||
package com.king.zxing;
|
package com.king.zxing;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import androidx.test.InstrumentationRegistry;
|
import androidx.test.InstrumentationRegistry;
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instrumented test, which will execute on an Android device.
|
* Instrumented test, which will execute on an Android device.
|
||||||
*
|
*
|
||||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||||
*/
|
*/
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class ExampleInstrumentedTest {
|
public class ExampleInstrumentedTest {
|
||||||
@Test
|
@Test
|
||||||
public void useAppContext() {
|
public void useAppContext() {
|
||||||
// Context of the app under test.
|
// Context of the app under test.
|
||||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
|
||||||
assertEquals("com.king.zxing.test", appContext.getPackageName());
|
assertEquals("com.king.zxing.test", appContext.getPackageName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.king.zxing">
|
package="com.king.zxing">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.CAMERA"/>
|
<uses-permission android:name="android.permission.CAMERA"/>
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
<uses-permission android:name="android.permission.FLASHLIGHT"/>
|
<uses-permission android:name="android.permission.FLASHLIGHT"/>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||||
|
|
||||||
<application>
|
<application>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,214 +1,214 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jenly Yu
|
* Copyright (C) 2018 Jenly Yu
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.king.zxing;
|
package com.king.zxing;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.google.zxing.Result;
|
import com.google.zxing.Result;
|
||||||
import com.king.zxing.util.LogUtils;
|
import com.king.zxing.util.LogUtils;
|
||||||
import com.king.zxing.util.PermissionUtils;
|
import com.king.zxing.util.PermissionUtils;
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.camera.view.PreviewView;
|
import androidx.camera.view.PreviewView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||||
*/
|
*/
|
||||||
public class CaptureActivity extends AppCompatActivity implements CameraScan.OnScanResultCallback{
|
public class CaptureActivity extends AppCompatActivity implements CameraScan.OnScanResultCallback{
|
||||||
|
|
||||||
private static final int CAMERA_PERMISSION_REQUEST_CODE = 0X86;
|
private static final int CAMERA_PERMISSION_REQUEST_CODE = 0X86;
|
||||||
|
|
||||||
protected PreviewView previewView;
|
protected PreviewView previewView;
|
||||||
protected ViewfinderView viewfinderView;
|
protected ViewfinderView viewfinderView;
|
||||||
protected View ivFlashlight;
|
protected View ivFlashlight;
|
||||||
|
|
||||||
private CameraScan mCameraScan;
|
private CameraScan mCameraScan;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
int layoutId = getLayoutId();
|
int layoutId = getLayoutId();
|
||||||
if(isContentView(layoutId)){
|
if(isContentView(layoutId)){
|
||||||
setContentView(layoutId);
|
setContentView(layoutId);
|
||||||
}
|
}
|
||||||
initUI();
|
initUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化
|
* 初始化
|
||||||
*/
|
*/
|
||||||
public void initUI(){
|
public void initUI(){
|
||||||
previewView = findViewById(getPreviewViewId());
|
previewView = findViewById(getPreviewViewId());
|
||||||
int viewfinderViewId = getViewfinderViewId();
|
int viewfinderViewId = getViewfinderViewId();
|
||||||
if(viewfinderViewId != 0){
|
if(viewfinderViewId != 0){
|
||||||
viewfinderView = findViewById(viewfinderViewId);
|
viewfinderView = findViewById(viewfinderViewId);
|
||||||
}
|
}
|
||||||
int ivFlashlightId = getFlashlightId();
|
int ivFlashlightId = getFlashlightId();
|
||||||
if(ivFlashlightId != 0){
|
if(ivFlashlightId != 0){
|
||||||
ivFlashlight = findViewById(ivFlashlightId);
|
ivFlashlight = findViewById(ivFlashlightId);
|
||||||
if(ivFlashlight != null){
|
if(ivFlashlight != null){
|
||||||
ivFlashlight.setOnClickListener(v -> onClickFlashlight());
|
ivFlashlight.setOnClickListener(v -> onClickFlashlight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initCameraScan();
|
initCameraScan();
|
||||||
startCamera();
|
startCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 点击手电筒
|
* 点击手电筒
|
||||||
*/
|
*/
|
||||||
protected void onClickFlashlight(){
|
protected void onClickFlashlight(){
|
||||||
toggleTorchState();
|
toggleTorchState();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化CameraScan
|
* 初始化CameraScan
|
||||||
*/
|
*/
|
||||||
public void initCameraScan(){
|
public void initCameraScan(){
|
||||||
mCameraScan = new DefaultCameraScan(this,previewView);
|
mCameraScan = new DefaultCameraScan(this,previewView);
|
||||||
mCameraScan.setOnScanResultCallback(this);
|
mCameraScan.setOnScanResultCallback(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动相机预览
|
* 启动相机预览
|
||||||
*/
|
*/
|
||||||
public void startCamera(){
|
public void startCamera(){
|
||||||
if(mCameraScan != null){
|
if(mCameraScan != null){
|
||||||
if(PermissionUtils.checkPermission(this,Manifest.permission.CAMERA)){
|
if(PermissionUtils.checkPermission(this,Manifest.permission.CAMERA)){
|
||||||
mCameraScan.startCamera();
|
mCameraScan.startCamera();
|
||||||
}else{
|
}else{
|
||||||
LogUtils.d("checkPermissionResult != PERMISSION_GRANTED");
|
LogUtils.d("checkPermissionResult != PERMISSION_GRANTED");
|
||||||
PermissionUtils.requestPermission(this,Manifest.permission.CAMERA,CAMERA_PERMISSION_REQUEST_CODE);
|
PermissionUtils.requestPermission(this,Manifest.permission.CAMERA,CAMERA_PERMISSION_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 释放相机
|
* 释放相机
|
||||||
*/
|
*/
|
||||||
private void releaseCamera(){
|
private void releaseCamera(){
|
||||||
if(mCameraScan != null){
|
if(mCameraScan != null){
|
||||||
mCameraScan.release();
|
mCameraScan.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 切换闪光灯状态(开启/关闭)
|
* 切换闪光灯状态(开启/关闭)
|
||||||
*/
|
*/
|
||||||
protected void toggleTorchState(){
|
protected void toggleTorchState(){
|
||||||
if(mCameraScan != null){
|
if(mCameraScan != null){
|
||||||
boolean isTorch = mCameraScan.isTorchEnabled();
|
boolean isTorch = mCameraScan.isTorchEnabled();
|
||||||
mCameraScan.enableTorch(!isTorch);
|
mCameraScan.enableTorch(!isTorch);
|
||||||
if(ivFlashlight != null){
|
if(ivFlashlight != null){
|
||||||
ivFlashlight.setSelected(!isTorch);
|
ivFlashlight.setSelected(!isTorch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
if(requestCode == CAMERA_PERMISSION_REQUEST_CODE){
|
if(requestCode == CAMERA_PERMISSION_REQUEST_CODE){
|
||||||
requestCameraPermissionResult(permissions,grantResults);
|
requestCameraPermissionResult(permissions,grantResults);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求Camera权限回调结果
|
* 请求Camera权限回调结果
|
||||||
* @param permissions
|
* @param permissions
|
||||||
* @param grantResults
|
* @param grantResults
|
||||||
*/
|
*/
|
||||||
public void requestCameraPermissionResult(@NonNull String[] permissions, @NonNull int[] grantResults){
|
public void requestCameraPermissionResult(@NonNull String[] permissions, @NonNull int[] grantResults){
|
||||||
if(PermissionUtils.requestPermissionsResult(Manifest.permission.CAMERA,permissions,grantResults)){
|
if(PermissionUtils.requestPermissionsResult(Manifest.permission.CAMERA,permissions,grantResults)){
|
||||||
startCamera();
|
startCamera();
|
||||||
}else{
|
}else{
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
releaseCamera();
|
releaseCamera();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回true时会自动初始化{@link #setContentView(int)},返回为false是需自己去初始化{@link #setContentView(int)}
|
* 返回true时会自动初始化{@link #setContentView(int)},返回为false是需自己去初始化{@link #setContentView(int)}
|
||||||
* @param layoutId
|
* @param layoutId
|
||||||
* @return 默认返回true
|
* @return 默认返回true
|
||||||
*/
|
*/
|
||||||
public boolean isContentView(@LayoutRes int layoutId){
|
public boolean isContentView(@LayoutRes int layoutId){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 布局id
|
* 布局id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int getLayoutId(){
|
public int getLayoutId(){
|
||||||
return R.layout.zxl_capture;
|
return R.layout.zxl_capture;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link #viewfinderView} 的 ID
|
* {@link #viewfinderView} 的 ID
|
||||||
* @return 默认返回{@code R.id.viewfinderView}, 如果不需要扫码框可以返回0
|
* @return 默认返回{@code R.id.viewfinderView}, 如果不需要扫码框可以返回0
|
||||||
*/
|
*/
|
||||||
public int getViewfinderViewId(){
|
public int getViewfinderViewId(){
|
||||||
return R.id.viewfinderView;
|
return R.id.viewfinderView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预览界面{@link #previewView} 的ID
|
* 预览界面{@link #previewView} 的ID
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int getPreviewViewId(){
|
public int getPreviewViewId(){
|
||||||
return R.id.previewView;
|
return R.id.previewView;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 {@link #ivFlashlight} 的ID
|
* 获取 {@link #ivFlashlight} 的ID
|
||||||
* @return 默认返回{@code R.id.ivFlashlight}, 如果不需要手电筒按钮可以返回0
|
* @return 默认返回{@code R.id.ivFlashlight}, 如果不需要手电筒按钮可以返回0
|
||||||
*/
|
*/
|
||||||
public int getFlashlightId(){
|
public int getFlashlightId(){
|
||||||
return R.id.ivFlashlight;
|
return R.id.ivFlashlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get {@link CameraScan}
|
* Get {@link CameraScan}
|
||||||
* @return {@link #mCameraScan}
|
* @return {@link #mCameraScan}
|
||||||
*/
|
*/
|
||||||
public CameraScan getCameraScan(){
|
public CameraScan getCameraScan(){
|
||||||
return mCameraScan;
|
return mCameraScan;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接收扫码结果回调
|
* 接收扫码结果回调
|
||||||
* @param result 扫码结果
|
* @param result 扫码结果
|
||||||
* @return 返回true表示拦截,将不自动执行后续逻辑,为false表示不拦截,默认不拦截
|
* @return 返回true表示拦截,将不自动执行后续逻辑,为false表示不拦截,默认不拦截
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onScanResultCallback(Result result) {
|
public boolean onScanResultCallback(Result result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,8 @@ import com.google.zxing.ResultPoint;
|
|||||||
import com.google.zxing.common.detector.MathUtils;
|
import com.google.zxing.common.detector.MathUtils;
|
||||||
import com.king.zxing.analyze.Analyzer;
|
import com.king.zxing.analyze.Analyzer;
|
||||||
import com.king.zxing.analyze.MultiFormatAnalyzer;
|
import com.king.zxing.analyze.MultiFormatAnalyzer;
|
||||||
|
import com.king.zxing.manager.AmbientLightManager;
|
||||||
|
import com.king.zxing.manager.BeepManager;
|
||||||
import com.king.zxing.util.LogUtils;
|
import com.king.zxing.util.LogUtils;
|
||||||
|
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,151 +1,151 @@
|
|||||||
package com.king.zxing;
|
package com.king.zxing.manager;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2012 ZXing authors
|
* Copyright (C) 2012 ZXing authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
import android.hardware.SensorEvent;
|
import android.hardware.SensorEvent;
|
||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
import android.hardware.SensorManager;
|
import android.hardware.SensorManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||||
*/
|
*/
|
||||||
public class AmbientLightManager implements SensorEventListener {
|
public class AmbientLightManager implements SensorEventListener {
|
||||||
|
|
||||||
private static final int INTERVAL_TIME = 200;
|
private static final int INTERVAL_TIME = 200;
|
||||||
|
|
||||||
protected static final float DARK_LUX = 45.0f;
|
protected static final float DARK_LUX = 45.0f;
|
||||||
protected static final float BRIGHT_LUX = 100.0f;
|
protected static final float BRIGHT_LUX = 100.0f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 光线太暗时,默认:照度45 lux
|
* 光线太暗时,默认:照度45 lux
|
||||||
*/
|
*/
|
||||||
private float darkLightLux = DARK_LUX;
|
private float darkLightLux = DARK_LUX;
|
||||||
/**
|
/**
|
||||||
* 光线足够亮时,默认:照度100 lux
|
* 光线足够亮时,默认:照度100 lux
|
||||||
*/
|
*/
|
||||||
private float brightLightLux = BRIGHT_LUX;
|
private float brightLightLux = BRIGHT_LUX;
|
||||||
|
|
||||||
private SensorManager sensorManager;
|
private SensorManager sensorManager;
|
||||||
private Sensor lightSensor;
|
private Sensor lightSensor;
|
||||||
|
|
||||||
private long lastTime;
|
private long lastTime;
|
||||||
|
|
||||||
private boolean isLightSensorEnabled;
|
private boolean isLightSensorEnabled;
|
||||||
|
|
||||||
private OnLightSensorEventListener mOnLightSensorEventListener;
|
private OnLightSensorEventListener mOnLightSensorEventListener;
|
||||||
|
|
||||||
AmbientLightManager(Context context) {
|
public AmbientLightManager(Context context) {
|
||||||
sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||||
lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
|
lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
|
||||||
isLightSensorEnabled = true;
|
isLightSensorEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register() {
|
public void register() {
|
||||||
if (sensorManager != null && lightSensor != null) {
|
if (sensorManager != null && lightSensor != null) {
|
||||||
sensorManager.registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
sensorManager.registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregister() {
|
public void unregister() {
|
||||||
if (sensorManager != null && lightSensor != null) {
|
if (sensorManager != null && lightSensor != null) {
|
||||||
sensorManager.unregisterListener(this);
|
sensorManager.unregisterListener(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSensorChanged(SensorEvent sensorEvent) {
|
public void onSensorChanged(SensorEvent sensorEvent) {
|
||||||
if(isLightSensorEnabled){
|
if(isLightSensorEnabled){
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
if(currentTime - lastTime < INTERVAL_TIME){//降低频率
|
if(currentTime - lastTime < INTERVAL_TIME){//降低频率
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lastTime = currentTime;
|
lastTime = currentTime;
|
||||||
|
|
||||||
if (mOnLightSensorEventListener != null) {
|
if (mOnLightSensorEventListener != null) {
|
||||||
float lightLux = sensorEvent.values[0];
|
float lightLux = sensorEvent.values[0];
|
||||||
mOnLightSensorEventListener.onSensorChanged(lightLux);
|
mOnLightSensorEventListener.onSensorChanged(lightLux);
|
||||||
if (lightLux <= darkLightLux) {
|
if (lightLux <= darkLightLux) {
|
||||||
mOnLightSensorEventListener.onSensorChanged(true,darkLightLux);
|
mOnLightSensorEventListener.onSensorChanged(true,lightLux);
|
||||||
} else if (lightLux >= brightLightLux) {
|
} else if (lightLux >= brightLightLux) {
|
||||||
mOnLightSensorEventListener.onSensorChanged(false,darkLightLux);
|
mOnLightSensorEventListener.onSensorChanged(false,lightLux);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置光线足够暗的阈值(单位:lux)
|
* 设置光线足够暗的阈值(单位:lux)
|
||||||
* @param lightLux
|
* @param lightLux
|
||||||
*/
|
*/
|
||||||
public void setDarkLightLux(float lightLux){
|
public void setDarkLightLux(float lightLux){
|
||||||
this.darkLightLux = lightLux;
|
this.darkLightLux = lightLux;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置光线足够明亮的阈值(单位:lux)
|
* 设置光线足够明亮的阈值(单位:lux)
|
||||||
* @param lightLux
|
* @param lightLux
|
||||||
*/
|
*/
|
||||||
public void setBrightLightLux(float lightLux){
|
public void setBrightLightLux(float lightLux){
|
||||||
this.brightLightLux = lightLux;
|
this.brightLightLux = lightLux;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLightSensorEnabled() {
|
public boolean isLightSensorEnabled() {
|
||||||
return isLightSensorEnabled;
|
return isLightSensorEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置是否启用光线亮度传感器
|
* 设置是否启用光线亮度传感器
|
||||||
* @param lightSensorEnabled
|
* @param lightSensorEnabled
|
||||||
*/
|
*/
|
||||||
public void setLightSensorEnabled(boolean lightSensorEnabled) {
|
public void setLightSensorEnabled(boolean lightSensorEnabled) {
|
||||||
isLightSensorEnabled = lightSensorEnabled;
|
isLightSensorEnabled = lightSensorEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置光线亮度传感器监听器,只有在 {@link #isLightSensorEnabled} 为{@code true} 才有效
|
* 设置光线亮度传感器监听器,只有在 {@link #isLightSensorEnabled} 为{@code true} 才有效
|
||||||
* @param listener
|
* @param listener
|
||||||
*/
|
*/
|
||||||
public void setOnLightSensorEventListener(OnLightSensorEventListener listener){
|
public void setOnLightSensorEventListener(OnLightSensorEventListener listener){
|
||||||
mOnLightSensorEventListener = listener;
|
mOnLightSensorEventListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnLightSensorEventListener{
|
public interface OnLightSensorEventListener{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param lightLux 当前检测到的光线照度值
|
* @param lightLux 当前检测到的光线照度值
|
||||||
*/
|
*/
|
||||||
default void onSensorChanged(float lightLux){
|
default void onSensorChanged(float lightLux){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 传感器改变事件
|
* 传感器改变事件
|
||||||
* @param dark 是否太暗了,当检测到的光线照度值小于{@link #darkLightLux}时,为{@code true}
|
* @param dark 是否太暗了,当检测到的光线照度值小于{@link #darkLightLux}时,为{@code true}
|
||||||
* @param lightLux 当前检测到的光线照度值
|
* @param lightLux 当前检测到的光线照度值
|
||||||
*/
|
*/
|
||||||
void onSensorChanged(boolean dark,float lightLux);
|
void onSensorChanged(boolean dark,float lightLux);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,110 +1,111 @@
|
|||||||
package com.king.zxing;
|
package com.king.zxing.manager;
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2010 ZXing authors
|
* Copyright (C) 2010 ZXing authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.AssetFileDescriptor;
|
import android.content.res.AssetFileDescriptor;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
|
|
||||||
import com.king.zxing.util.LogUtils;
|
import com.king.zxing.R;
|
||||||
|
import com.king.zxing.util.LogUtils;
|
||||||
import java.io.Closeable;
|
|
||||||
|
import java.io.Closeable;
|
||||||
/**
|
|
||||||
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
/**
|
||||||
*/
|
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||||
public final class BeepManager implements MediaPlayer.OnErrorListener, Closeable {
|
*/
|
||||||
|
public final class BeepManager implements MediaPlayer.OnErrorListener, Closeable {
|
||||||
private static final long VIBRATE_DURATION = 200L;
|
|
||||||
|
private static final long VIBRATE_DURATION = 200L;
|
||||||
private final Context context;
|
|
||||||
private MediaPlayer mediaPlayer;
|
private final Context context;
|
||||||
private Vibrator vibrator;
|
private MediaPlayer mediaPlayer;
|
||||||
private boolean playBeep;
|
private Vibrator vibrator;
|
||||||
private boolean vibrate;
|
private boolean playBeep;
|
||||||
|
private boolean vibrate;
|
||||||
BeepManager(Context context) {
|
|
||||||
this.context = context;
|
public BeepManager(Context context) {
|
||||||
this.mediaPlayer = null;
|
this.context = context;
|
||||||
updatePrefs();
|
this.mediaPlayer = null;
|
||||||
}
|
updatePrefs();
|
||||||
|
}
|
||||||
public void setVibrate(boolean vibrate){
|
|
||||||
this.vibrate = vibrate;
|
public void setVibrate(boolean vibrate){
|
||||||
}
|
this.vibrate = vibrate;
|
||||||
|
}
|
||||||
public void setPlayBeep(boolean playBeep){
|
|
||||||
this.playBeep = playBeep;
|
public void setPlayBeep(boolean playBeep){
|
||||||
}
|
this.playBeep = playBeep;
|
||||||
|
}
|
||||||
private synchronized void updatePrefs() {
|
|
||||||
if (mediaPlayer == null) {
|
private synchronized void updatePrefs() {
|
||||||
mediaPlayer = buildMediaPlayer(context);
|
if (mediaPlayer == null) {
|
||||||
}
|
mediaPlayer = buildMediaPlayer(context);
|
||||||
if(vibrator == null){
|
}
|
||||||
vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
|
if(vibrator == null){
|
||||||
}
|
vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public synchronized void playBeepSoundAndVibrate() {
|
|
||||||
if (playBeep && mediaPlayer != null) {
|
public synchronized void playBeepSoundAndVibrate() {
|
||||||
mediaPlayer.start();
|
if (playBeep && mediaPlayer != null) {
|
||||||
}
|
mediaPlayer.start();
|
||||||
if (vibrate) {
|
}
|
||||||
vibrator.vibrate(VIBRATE_DURATION);
|
if (vibrate) {
|
||||||
}
|
vibrator.vibrate(VIBRATE_DURATION);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private MediaPlayer buildMediaPlayer(Context context) {
|
|
||||||
MediaPlayer mediaPlayer = new MediaPlayer();
|
private MediaPlayer buildMediaPlayer(Context context) {
|
||||||
try {
|
MediaPlayer mediaPlayer = new MediaPlayer();
|
||||||
AssetFileDescriptor file = context.getResources().openRawResourceFd(R.raw.zxl_beep);
|
try {
|
||||||
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
|
AssetFileDescriptor file = context.getResources().openRawResourceFd(R.raw.zxl_beep);
|
||||||
mediaPlayer.setOnErrorListener(this);
|
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
|
||||||
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
mediaPlayer.setOnErrorListener(this);
|
||||||
mediaPlayer.setLooping(false);
|
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||||
mediaPlayer.prepare();
|
mediaPlayer.setLooping(false);
|
||||||
return mediaPlayer;
|
mediaPlayer.prepare();
|
||||||
} catch (Exception e) {
|
return mediaPlayer;
|
||||||
LogUtils.w(e);
|
} catch (Exception e) {
|
||||||
mediaPlayer.release();
|
LogUtils.w(e);
|
||||||
return null;
|
mediaPlayer.release();
|
||||||
}
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
|
@Override
|
||||||
close();
|
public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
|
||||||
updatePrefs();
|
close();
|
||||||
return true;
|
updatePrefs();
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public synchronized void close() {
|
@Override
|
||||||
try{
|
public synchronized void close() {
|
||||||
if (mediaPlayer != null) {
|
try{
|
||||||
mediaPlayer.release();
|
if (mediaPlayer != null) {
|
||||||
mediaPlayer = null;
|
mediaPlayer.release();
|
||||||
}
|
mediaPlayer = null;
|
||||||
}catch (Exception e){
|
}
|
||||||
LogUtils.e(e);
|
}catch (Exception e){
|
||||||
}
|
LogUtils.e(e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
@@ -1,46 +1,46 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<declare-styleable name="ViewfinderView">
|
<declare-styleable name="ViewfinderView">
|
||||||
<attr name="maskColor" format="color" />
|
<attr name="maskColor" format="color" />
|
||||||
<attr name="frameColor" format="color" />
|
<attr name="frameColor" format="color" />
|
||||||
<attr name="cornerColor" format="color"/>
|
<attr name="cornerColor" format="color"/>
|
||||||
<attr name="laserColor" format="color"/>
|
<attr name="laserColor" format="color"/>
|
||||||
<attr name="labelText" format="string"/>
|
<attr name="labelText" format="string"/>
|
||||||
<attr name="labelTextColor" format="color"/>
|
<attr name="labelTextColor" format="color"/>
|
||||||
<attr name="labelTextSize" format="dimension"/>
|
<attr name="labelTextSize" format="dimension"/>
|
||||||
<attr name="labelTextPadding" format="dimension"/>
|
<attr name="labelTextPadding" format="dimension"/>
|
||||||
<attr name="labelTextWidth" format="dimension"/>
|
<attr name="labelTextWidth" format="dimension"/>
|
||||||
<attr name="labelTextLocation" format="enum">
|
<attr name="labelTextLocation" format="enum">
|
||||||
<enum name="top" value="0"/>
|
<enum name="top" value="0"/>
|
||||||
<enum name="bottom" value="1"/>
|
<enum name="bottom" value="1"/>
|
||||||
</attr>
|
</attr>
|
||||||
<attr name="frameWidth" format="dimension"/>
|
<attr name="frameWidth" format="dimension"/>
|
||||||
<attr name="frameHeight" format="dimension"/>
|
<attr name="frameHeight" format="dimension"/>
|
||||||
<attr name="gridColumn" format="integer"/>
|
<attr name="gridColumn" format="integer"/>
|
||||||
<attr name="gridHeight" format="dimension"/>
|
<attr name="gridHeight" format="dimension"/>
|
||||||
<attr name="laserStyle" format="enum">
|
<attr name="laserStyle" format="enum">
|
||||||
<enum name="none" value="0"/>
|
<enum name="none" value="0"/>
|
||||||
<enum name="line" value="1"/>
|
<enum name="line" value="1"/>
|
||||||
<enum name="grid" value="2"/>
|
<enum name="grid" value="2"/>
|
||||||
</attr>
|
</attr>
|
||||||
<attr name="cornerRectWidth" format="dimension"/>
|
<attr name="cornerRectWidth" format="dimension"/>
|
||||||
<attr name="cornerRectHeight" format="dimension"/>
|
<attr name="cornerRectHeight" format="dimension"/>
|
||||||
<attr name="scannerLineMoveDistance" format="dimension"/>
|
<attr name="scannerLineMoveDistance" format="dimension"/>
|
||||||
<attr name="scannerLineHeight" format="dimension"/>
|
<attr name="scannerLineHeight" format="dimension"/>
|
||||||
<attr name="frameLineWidth" format="dimension"/>
|
<attr name="frameLineWidth" format="dimension"/>
|
||||||
<attr name="scannerAnimationDelay" format="integer"/>
|
<attr name="scannerAnimationDelay" format="integer"/>
|
||||||
<attr name="frameRatio" format="float"/>
|
<attr name="frameRatio" format="float"/>
|
||||||
<attr name="framePaddingLeft" format="dimension"/>
|
<attr name="framePaddingLeft" format="dimension"/>
|
||||||
<attr name="framePaddingTop" format="dimension"/>
|
<attr name="framePaddingTop" format="dimension"/>
|
||||||
<attr name="framePaddingRight" format="dimension"/>
|
<attr name="framePaddingRight" format="dimension"/>
|
||||||
<attr name="framePaddingBottom" format="dimension"/>
|
<attr name="framePaddingBottom" format="dimension"/>
|
||||||
<attr name="frameGravity" format="enum">
|
<attr name="frameGravity" format="enum">
|
||||||
<enum name="center" value="0"/>
|
<enum name="center" value="0"/>
|
||||||
<enum name="left" value="1"/>
|
<enum name="left" value="1"/>
|
||||||
<enum name="top" value="2"/>
|
<enum name="top" value="2"/>
|
||||||
<enum name="right" value="3"/>
|
<enum name="right" value="3"/>
|
||||||
<enum name="bottom" value="4"/>
|
<enum name="bottom" value="4"/>
|
||||||
</attr>
|
</attr>
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<color name="viewfinder_mask">#60000000</color>
|
<color name="viewfinder_mask">#60000000</color>
|
||||||
<color name="viewfinder_frame">#7F1FB3E2</color>
|
<color name="viewfinder_frame">#7F1FB3E2</color>
|
||||||
<color name="viewfinder_corner">#FF1FB3E2</color>
|
<color name="viewfinder_corner">#FF1FB3E2</color>
|
||||||
<color name="viewfinder_laser">#FF1FB3E2</color>
|
<color name="viewfinder_laser">#FF1FB3E2</color>
|
||||||
<color name="viewfinder_text_color">#FFC0C0C0</color>
|
<color name="viewfinder_text_color">#FFC0C0C0</color>
|
||||||
|
|
||||||
<color name="zxl_capture_status_bar_color">#00000000</color>
|
<color name="zxl_capture_status_bar_color">#00000000</color>
|
||||||
<color name="zxl_capture_navigation_bar_color">#00000000</color>
|
<color name="zxl_capture_navigation_bar_color">#00000000</color>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
package com.king.zxing;
|
package com.king.zxing;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example local unit test, which will execute on the development machine (host).
|
* Example local unit test, which will execute on the development machine (host).
|
||||||
*
|
*
|
||||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||||
*/
|
*/
|
||||||
public class ExampleUnitTest {
|
public class ExampleUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void addition_isCorrect() {
|
public void addition_isCorrect() {
|
||||||
assertEquals(4, 2 + 2);
|
assertEquals(4, 2 + 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user