Repository: liang530/ScanCode
Branch: master
Commit: 404dbb4ca783
Files: 74
Total size: 127.1 KB
Directory structure:
gitextract_qo_l_5id/
├── .gitignore
├── .idea/
│ ├── .name
│ ├── compiler.xml
│ ├── copyright/
│ │ └── profiles_settings.xml
│ ├── encodings.xml
│ ├── gradle.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ └── vcs.xml
├── README.md
├── ScanCode.iml
├── app/
│ ├── .gitignore
│ ├── app.iml
│ ├── build.gradle
│ ├── libs/
│ │ ├── butterknife-7.0.1.jar
│ │ └── zxing.jar
│ ├── proguard-rules.pro
│ └── src/
│ └── main/
│ ├── AndroidManifest.xml
│ ├── java/
│ │ └── com/
│ │ └── liang/
│ │ └── scancode/
│ │ ├── CommonScanActivity.java
│ │ ├── CreateCodeActivity.java
│ │ ├── MainActivity.java
│ │ ├── defineview/
│ │ │ └── MyImageView.java
│ │ ├── utils/
│ │ │ └── Constant.java
│ │ └── zxing/
│ │ ├── ScanListener.java
│ │ ├── ScanManager.java
│ │ ├── camera/
│ │ │ ├── AutoFocusManager.java
│ │ │ ├── CameraConfigurationManager.java
│ │ │ ├── CameraManager.java
│ │ │ ├── PreviewCallback.java
│ │ │ └── open/
│ │ │ └── OpenCameraInterface.java
│ │ ├── decode/
│ │ │ ├── DecodeFormatManager.java
│ │ │ ├── DecodeHandler.java
│ │ │ ├── DecodeThread.java
│ │ │ ├── PhotoScanHandler.java
│ │ │ ├── RGBLuminanceSource.java
│ │ │ └── Utils.java
│ │ ├── encode/
│ │ │ └── EncodingHandler.java
│ │ └── utils/
│ │ ├── AppliationUtil.java
│ │ ├── BeepManager.java
│ │ ├── BitmapUtil.java
│ │ ├── CaptureActivityHandler.java
│ │ └── InactivityTimer.java
│ └── res/
│ ├── anim/
│ │ ├── popupwin_nearperson_exit.xml
│ │ ├── popupwin_nearperson_show.xml
│ │ ├── shouquan_dialog_enter.xml
│ │ └── shouquan_dialog_exit.xml
│ ├── drawable/
│ │ ├── base_bgpic.xml
│ │ ├── rescan_shape_button.xml
│ │ ├── shouquan_bg_loading_dialog_shape.xml
│ │ ├── shouquan_loading_dialog_progressbar.xml
│ │ ├── shouquan_qrcode_g_gallery.xml
│ │ ├── shouquan_qrcode_ic_back.xml
│ │ └── shouquan_qrcode_s_flashgun.xml
│ ├── layout/
│ │ ├── activity_create_code.xml
│ │ ├── activity_main.xml
│ │ ├── activity_scan_code.xml
│ │ └── activity_scan_result.xml
│ ├── menu/
│ │ ├── menu_jump_to.xml
│ │ └── menu_sao_mao.xml
│ ├── raw/
│ │ └── beep.ogg
│ ├── values/
│ │ ├── Qrcode_ids.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── values-w820dp/
│ └── dimens.xml
├── build.gradle
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
### Android template
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
================================================
FILE: .idea/.name
================================================
ScanCode
================================================
FILE: .idea/compiler.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>
================================================
FILE: .idea/copyright/profiles_settings.xml
================================================
<component name="CopyrightManager">
<settings default="" />
</component>
================================================
FILE: .idea/encodings.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
================================================
FILE: .idea/gradle.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:\android\android-studio\gradle\gradle-2.4" />
<option name="gradleJvm" value="1.8" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>
================================================
FILE: .idea/misc.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
================================================
FILE: .idea/modules.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/ScanCode.iml" filepath="$PROJECT_DIR$/ScanCode.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
</project>
================================================
FILE: .idea/runConfigurations.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
================================================
FILE: .idea/vcs.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
================================================
FILE: README.md
================================================
# ScanCode
使用zxing封装的android扫描全功能系列,包括二维码扫描,条形码扫描,二维码生成,条形码生成,从图片中扫描二维码或者条形码,闪光灯控制。<br/>
优点:<br/>
1.该有的功能一个都不少!<br/>
2.扫描界面布局xml完成,可自行订制!<br/>
3.不乱码,不变形!<br/>
4.扫描后可得到扫描的截图!<br/>
5.支持连续扫描!<br/>
6.在一个项目中可多处使用,根据CommonScanActivity在多写一个自己的扫描界面就行了!<br/>
#项目截图
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
================================================
FILE: ScanCode.iml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="ScanCode" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
================================================
FILE: app/.gitignore
================================================
### Android template
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
/build
================================================
FILE: app/app.iml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="ScanCode" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":app" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
<afterSyncTasks>
<task>generateDebugAndroidTestSources</task>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="butterknife-7.0.1" level="project" />
<orderEntry type="library" exported="" name="zxing" level="project" />
</component>
</module>
================================================
FILE: app/build.gradle
================================================
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.liang.scancode"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
================================================
FILE: app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/hongliang/android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class goodsid to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: app/src/main/AndroidManifest.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.liang.scancode">
<!-- 二维码相关权限 -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".CreateCodeActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".CommonScanActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar" />
</application>
</manifest>
================================================
FILE: app/src/main/java/com/liang/scancode/CommonScanActivity.java
================================================
/*
* 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.liang.scancode;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.zxing.Result;
import butterknife.ButterKnife;
import butterknife.Bind;
import com.liang.scancode.utils.Constant;
import com.liang.scancode.zxing.ScanListener;
import com.liang.scancode.zxing.ScanManager;
import com.liang.scancode.zxing.decode.DecodeThread;
import com.liang.scancode.zxing.decode.Utils;
/**
* 二维码扫描使用
*
* @author 刘红亮 2015年4月29日 下午5:49:45
*/
public final class CommonScanActivity extends Activity implements ScanListener, View.OnClickListener {
static final String TAG = CommonScanActivity.class.getSimpleName();
SurfaceView scanPreview = null;
View scanContainer;
View scanCropView;
ImageView scanLine;
ScanManager scanManager;
TextView iv_light;
TextView qrcode_g_gallery;
TextView qrcode_ic_back;
final int PHOTOREQUESTCODE = 1111;
@Bind(R.id.service_register_rescan)
Button rescan;
@Bind(R.id.scan_image)
ImageView scan_image;
@Bind(R.id.authorize_return)
ImageView authorize_return;
private int scanMode;//扫描模型(条形,二维码,全部)
@Bind(R.id.common_title_TV_center)
TextView title;
@Bind(R.id.scan_hint)
TextView scan_hint;
@Bind(R.id.tv_scan_result)
TextView tv_scan_result;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_scan_code);
ButterKnife.bind(this);
scanMode=getIntent().getIntExtra(Constant.REQUEST_SCAN_MODE,Constant.REQUEST_SCAN_MODE_ALL_MODE);
initView();
}
void initView() {
switch (scanMode){
case DecodeThread.BARCODE_MODE:
title.setText(R.string.scan_barcode_title);
scan_hint.setText(R.string.scan_barcode_hint);
break;
case DecodeThread.QRCODE_MODE:
title.setText(R.string.scan_qrcode_title);
scan_hint.setText(R.string.scan_qrcode_hint);
break;
case DecodeThread.ALL_MODE:
title.setText(R.string.scan_allcode_title);
scan_hint.setText(R.string.scan_allcode_hint);
break;
}
scanPreview = (SurfaceView) findViewById(R.id.capture_preview);
scanContainer = findViewById(R.id.capture_container);
scanCropView = findViewById(R.id.capture_crop_view);
scanLine = (ImageView) findViewById(R.id.capture_scan_line);
qrcode_g_gallery = (TextView) findViewById(R.id.qrcode_g_gallery);
qrcode_g_gallery.setOnClickListener(this);
qrcode_ic_back = (TextView) findViewById(R.id.qrcode_ic_back);
qrcode_ic_back.setOnClickListener(this);
iv_light = (TextView) findViewById(R.id.iv_light);
iv_light.setOnClickListener(this);
rescan.setOnClickListener(this);
authorize_return.setOnClickListener(this);
//构造出扫描管理器
scanManager = new ScanManager(this, scanPreview, scanContainer, scanCropView, scanLine, scanMode,this);
}
@Override
public void onResume() {
super.onResume();
scanManager.onResume();
rescan.setVisibility(View.INVISIBLE);
scan_image.setVisibility(View.GONE);
}
@Override
public void onPause() {
super.onPause();
scanManager.onPause();
}
/**
*
*/
public void scanResult(Result rawResult, Bundle bundle) {
//扫描成功后,扫描器不会再连续扫描,如需连续扫描,调用reScan()方法。
//scanManager.reScan();
// Toast.makeText(that, "result="+rawResult.getText(), Toast.LENGTH_LONG).show();
if (!scanManager.isScanning()) { //如果当前不是在扫描状态
//设置再次扫描按钮出现
rescan.setVisibility(View.VISIBLE);
scan_image.setVisibility(View.VISIBLE);
Bitmap barcode = null;
byte[] compressedBitmap = bundle.getByteArray(DecodeThread.BARCODE_BITMAP);
if (compressedBitmap != null) {
barcode = BitmapFactory.decodeByteArray(compressedBitmap, 0, compressedBitmap.length, null);
barcode = barcode.copy(Bitmap.Config.ARGB_8888, true);
}
scan_image.setImageBitmap(barcode);
}
rescan.setVisibility(View.VISIBLE);
scan_image.setVisibility(View.VISIBLE);
tv_scan_result.setVisibility(View.VISIBLE);
tv_scan_result.setText("结果:"+rawResult.getText());
}
void startScan() {
if (rescan.getVisibility() == View.VISIBLE) {
rescan.setVisibility(View.INVISIBLE);
scan_image.setVisibility(View.GONE);
scanManager.reScan();
}
}
@Override
public void scanError(Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
//相机扫描出错时
if(e.getMessage()!=null&&e.getMessage().startsWith("相机")){
scanPreview.setVisibility(View.INVISIBLE);
}
}
public void showPictures(int requestCode) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, requestCode);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String photo_path;
if (resultCode == RESULT_OK) {
switch (requestCode) {
case PHOTOREQUESTCODE:
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = this.getContentResolver().query(data.getData(), proj, null, null, null);
if (cursor.moveToFirst()) {
int colum_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
photo_path = cursor.getString(colum_index);
if (photo_path == null) {
photo_path = Utils.getPath(getApplicationContext(), data.getData());
}
scanManager.scanningImage(photo_path);
}
}
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.qrcode_g_gallery:
showPictures(PHOTOREQUESTCODE);
break;
case R.id.iv_light:
scanManager.switchLight();
break;
case R.id.qrcode_ic_back:
finish();
break;
case R.id.service_register_rescan://再次开启扫描
startScan();
break;
case R.id.authorize_return:
finish();
break;
default:
break;
}
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/CreateCodeActivity.java
================================================
package com.liang.scancode;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import com.google.zxing.WriterException;
import java.io.UnsupportedEncodingException;
import butterknife.ButterKnife;
import butterknife.Bind;
import butterknife.OnClick;
import com.liang.scancode.zxing.encode.EncodingHandler;
/**
* Created by 刘红亮 on 2015/9/24 14:37.
*/
public class CreateCodeActivity extends Activity {
@Bind(R.id.et_code_key)
EditText etCodeKey;
@Bind(R.id.btn_create_code)
Button btnCreateCode;
@Bind(R.id.iv_2_code)
ImageView iv2Code;
@Bind(R.id.iv_bar_code)
ImageView ivBarCode;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_code);
ButterKnife.bind(this);
}
@OnClick({R.id.btn_create_code,R.id.btn_create_code_and_img})
public void clickListener(View view){
String key=etCodeKey.getText().toString();
switch (view.getId()){
case R.id.btn_create_code: //生成码
if(TextUtils.isEmpty(key)){
Toast.makeText(this,"请输入内容",Toast.LENGTH_SHORT).show();
}else{
create2Code(key);
createBarCode(key);
}
break;
case R.id.btn_create_code_and_img: //生成码
Bitmap bitmap = create2Code(key);
Bitmap headBitmap = getHeadBitmap(60);
if(bitmap!=null&&headBitmap!=null){
createQRCodeBitmapWithPortrait(bitmap,headBitmap);
}
break;
}
}
private Bitmap createBarCode(String key) {
Bitmap qrCode = null;
try {
qrCode = EncodingHandler.createBarCode(key, 600, 300);
ivBarCode.setImageBitmap(qrCode);
} catch (Exception e) {
Toast.makeText(this,"输入的内容条形码不支持!",Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
return qrCode;
}
/**
* 生成二维码
* @param key
*/
private Bitmap create2Code(String key) {
Bitmap qrCode=null;
try {
qrCode= EncodingHandler.create2Code(key, 400);
iv2Code.setImageBitmap(qrCode);
} catch (WriterException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return qrCode;
}
/**
* 初始化头像图片
*/
private Bitmap getHeadBitmap(int size) {
try {
// 这里采用从asset中加载图片abc.jpg
Bitmap portrait = BitmapFactory.decodeResource(getResources(),R.drawable.head);
// 对原有图片压缩显示大小
Matrix mMatrix = new Matrix();
float width = portrait.getWidth();
float height = portrait.getHeight();
mMatrix.setScale(size / width, size / height);
return Bitmap.createBitmap(portrait, 0, 0, (int) width,
(int) height, mMatrix, true);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 在二维码上绘制头像
*/
private void createQRCodeBitmapWithPortrait(Bitmap qr, Bitmap portrait) {
// 头像图片的大小
int portrait_W = portrait.getWidth();
int portrait_H = portrait.getHeight();
// 设置头像要显示的位置,即居中显示
int left = (qr.getWidth() - portrait_W) / 2;
int top = (qr.getHeight() - portrait_H) / 2;
int right = left + portrait_W;
int bottom = top + portrait_H;
Rect rect1 = new Rect(left, top, right, bottom);
// 取得qr二维码图片上的画笔,即要在二维码图片上绘制我们的头像
Canvas canvas = new Canvas(qr);
// 设置我们要绘制的范围大小,也就是头像的大小范围
Rect rect2 = new Rect(0, 0, portrait_W, portrait_H);
// 开始绘制
canvas.drawBitmap(portrait, rect2, rect1, null);
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/MainActivity.java
================================================
package com.liang.scancode;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.liang.scancode.utils.Constant;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
int mode = getIntent().getIntExtra(Constant.REQUEST_SCAN_MODE, Constant.REQUEST_SCAN_MODE_ALL_MODE);
}
/**
* 按钮监听事件,这里我使用Butterknife,不喜欢的也可以直接写监听
* @param view
*/
@OnClick({R.id.create_code,R.id.scan_2code,R.id.scan_bar_code,R.id.scan_code})
public void clickListener(View view){
Intent intent;
switch (view.getId()){
case R.id.create_code: //生成码
intent=new Intent(this,CreateCodeActivity.class);
startActivity(intent);
break;
case R.id.scan_2code: //扫描二维码
intent=new Intent(this,CommonScanActivity.class);
intent.putExtra(Constant.REQUEST_SCAN_MODE,Constant.REQUEST_SCAN_MODE_QRCODE_MODE);
startActivity(intent);
break;
case R.id.scan_bar_code://扫描条形码
intent=new Intent(this,CommonScanActivity.class);
intent.putExtra(Constant.REQUEST_SCAN_MODE,Constant.REQUEST_SCAN_MODE_BARCODE_MODE);
startActivity(intent);
break;
case R.id.scan_code://扫描条形码或者二维码
intent=new Intent(this,CommonScanActivity.class);
intent.putExtra(Constant.REQUEST_SCAN_MODE,Constant.REQUEST_SCAN_MODE_ALL_MODE);
startActivity(intent);
break;
}
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/defineview/MyImageView.java
================================================
package com.liang.scancode.defineview;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.ImageView;
/**
* 作者:王敏 on 2015/8/21 17:31
* 类说明:画出扫描框的四个脚的脚边框,也可以直接用一张图片代替
*/
public class MyImageView extends ImageView{
private Context context;
public MyImageView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
public MyImageView(Context context) {
super(context);
this.context = context;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int width = getWidth();
int height = getHeight();
Paint paint = new Paint();
paint.setColor(Color.rgb(9,187,7));
paint.setAntiAlias(true);
paint.setStrokeWidth(t(5));
canvas.drawLine(0, 0, 0, t(18), paint);
canvas.drawLine(0, 0, t(18), 0, paint);
canvas.drawLine(0, height - t(18), 0, height, paint);
canvas.drawLine(0, height, t(18),height,paint);
canvas.drawLine(width-t(18), 0, width, 0, paint);
canvas.drawLine(width, 0, width,t(18),paint);
canvas.drawLine(width, height-t(18), width, height, paint);
canvas.drawLine(width-t(18), height, width,height,paint);
}
public int dp2px(float dpVal)
{
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
dpVal, context.getResources().getDisplayMetrics());
}
public int t(float dpVal){
return dp2px(dpVal);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec,heightMeasureSpec);
// setMeasuredDimension(t(248),t(248));
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/utils/Constant.java
================================================
package com.liang.scancode.utils;
/**
* Created by 刘红亮 on 2015/9/24 14:08.
*/
public interface Constant {
/**
* 二维码请求的type
*/
public static final String REQUEST_SCAN_TYPE="type";
/**
* 普通类型,扫完即关闭
*/
public static final int REQUEST_SCAN_TYPE_COMMON=0;
/**
* 服务商登记类型,扫描
*/
public static final int REQUEST_SCAN_TYPE_REGIST=1;
/**
* 扫描类型
* 条形码或者二维码:REQUEST_SCAN_MODE_ALL_MODE
* 条形码: REQUEST_SCAN_MODE_BARCODE_MODE
* 二维码:REQUEST_SCAN_MODE_QRCODE_MODE
*
*/
public static final String REQUEST_SCAN_MODE="ScanMode";
/**
* 条形码: REQUEST_SCAN_MODE_BARCODE_MODE
*/
public static final int REQUEST_SCAN_MODE_BARCODE_MODE = 0X100;
/**
* 二维码:REQUEST_SCAN_MODE_ALL_MODE
*/
public static final int REQUEST_SCAN_MODE_QRCODE_MODE = 0X200;
/**
* 条形码或者二维码:REQUEST_SCAN_MODE_ALL_MODE
*/
public static final int REQUEST_SCAN_MODE_ALL_MODE = 0X300;
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/ScanListener.java
================================================
package com.liang.scancode.zxing;
import android.os.Bundle;
import com.google.zxing.Result;
/**
* 二维码结果监听返回
* @author 刘红亮 2015年4月29日 下午8:08:13
*
*/
public interface ScanListener {
/**
* 返回扫描结果
* @param rawResult 结果对象
* @param bundle 存放了截图,或者是空的
*/
public void scanResult(Result rawResult, Bundle bundle);
/**
* 扫描抛出的异常
* @param e
*/
public void scanError(Exception e);
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/ScanManager.java
================================================
package com.liang.scancode.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.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 com.liang.scancode.R;
import com.liang.scancode.zxing.camera.CameraManager;
import com.liang.scancode.zxing.decode.DecodeThread;
import com.liang.scancode.zxing.decode.PhotoScanHandler;
import com.liang.scancode.zxing.decode.RGBLuminanceSource;
import com.liang.scancode.zxing.utils.BeepManager;
import com.liang.scancode.zxing.utils.BitmapUtil;
import com.liang.scancode.zxing.utils.CaptureActivityHandler;
import com.liang.scancode.zxing.utils.InactivityTimer;
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);
}
/**
* 初始化截取的矩形区域
*/
void initCrop() {
int cameraWidth = cameraManager.getCameraResolution().y;
int cameraHeight = cameraManager.getCameraResolution().x;
/** 获取布局中扫描框的位置信息 */
int[] location = new int[2];
scanCropView.getLocationInWindow(location);
int cropLeft = location[0];
int cropTop = location[1] - getStatusBarHeight();
int cropWidth = scanCropView.getWidth();
int cropHeight = scanCropView.getHeight();
/** 获取布局容器的宽高 */
int containerWidth = scanContainer.getWidth();
int containerHeight = scanContainer.getHeight();
/** 计算最终截取的矩形的左上角顶点x坐标 */
int x = cropLeft * cameraWidth / containerWidth;
/** 计算最终截取的矩形的左上角顶点y坐标 */
int y = cropTop * cameraHeight / containerHeight;
/** 计算最终截取的矩形的宽度 */
int width = cropWidth * cameraWidth / containerWidth;
/** 计算最终截取的矩形的高度 */
int height = cropHeight * cameraHeight / containerHeight;
/** 生成最终的截取的矩形 */
mCropRect = new Rect(x, y, width + x, height + y);
}
int getStatusBarHeight() {
try {
Class<?> c = Class.forName("com.android.internal.R$dimen");
Object obj = c.newInstance();
Field field = c.getField("status_bar_height");
int x = Integer.parseInt(field.get(obj).toString());
return activity.getResources().getDimensionPixelSize(x);
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
/**
* 用于扫描本地图片二维码或者一维码
* @param photo_path2 本地图片的所在位置
* @return
*/
public void scanningImage(final String photo_path2) {
if(TextUtils.isEmpty(photo_path2)){
listener.scanError(new Exception("photo url is null!"));
}
photoScanHandler=new PhotoScanHandler(this);
new Thread(new Runnable() {
@Override
public void run() {
//获取初始化的设置器
Map<DecodeHintType, Object> hints = DecodeThread.getHints();
hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
// Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
Bitmap bitmap= BitmapUtil.decodeBitmapFromPath(photo_path2,600,600);
RGBLuminanceSource source = new RGBLuminanceSource(bitmap);
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
MultiFormatReader multiFormatReader=new MultiFormatReader();
try {
Message msg=Message.obtain();
msg.what=PhotoScanHandler.PHOTODECODEOK;
msg.obj = multiFormatReader.decode(bitmap1, hints);
photoScanHandler.sendMessage(msg);
} catch (Exception e) {
Message msg=Message.obtain();
msg.what=PhotoScanHandler.PHOTODECODEERROR;
msg.obj=new Exception("图片有误,或者图片模糊!");
photoScanHandler.sendMessage(msg);
}
}
}).start();
}
/**
* 扫描一次后,如需再次扫描,请调用这个方法
*/
public void reScan(){
if(handler!=null){
handler.sendEmptyMessage(R.id.restart_preview);
}
}
public boolean isScanning(){
if(handler!=null){
return handler.isScanning();
}
return false;
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/camera/AutoFocusManager.java
================================================
/*
* Copyright (C) 2012 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.liang.scancode.zxing.camera;
import android.annotation.SuppressLint;
import android.content.Context;
import android.hardware.Camera;
import android.os.AsyncTask;
import android.os.Build;
import android.util.Log;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.RejectedExecutionException;
public class AutoFocusManager implements Camera.AutoFocusCallback {
static final String TAG = AutoFocusManager.class.getSimpleName();
static final long AUTO_FOCUS_INTERVAL_MS = 2000L;
static final Collection<String> FOCUS_MODES_CALLING_AF;
static {
FOCUS_MODES_CALLING_AF = new ArrayList<String>(2);
FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_AUTO);
FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_MACRO);
}
boolean stopped;
boolean focusing;
final boolean useAutoFocus;
final Camera camera;
AsyncTask<?, ?, ?> outstandingTask;
public AutoFocusManager(Context context, Camera camera) {
this.camera = camera;
String currentFocusMode = camera.getParameters().getFocusMode();
useAutoFocus = FOCUS_MODES_CALLING_AF.contains(currentFocusMode);
Log.i(TAG, "Current focus mode '" + currentFocusMode + "'; use auto focus? " + useAutoFocus);
start();
}
@Override
public synchronized void onAutoFocus(boolean success, Camera theCamera) {
focusing = false;
autoFocusAgainLater();
}
@SuppressLint("NewApi")
synchronized void autoFocusAgainLater() {
if (!stopped && outstandingTask == null) {
AutoFocusTask newTask = new AutoFocusTask();
try {
if (Build.VERSION.SDK_INT >= 11) {
newTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
newTask.execute();
}
outstandingTask = newTask;
} catch (RejectedExecutionException ree) {
Log.w(TAG, "Could not request auto focus", ree);
}
}
}
public synchronized void start() {
if (useAutoFocus) {
outstandingTask = null;
if (!stopped && !focusing) {
try {
camera.autoFocus(this);
focusing = true;
} catch (RuntimeException re) {
// Have heard RuntimeException reported in Android 4.0.x+;
// continue?
Log.w(TAG, "Unexpected exception while focusing", re);
// Try again later to keep cycle going
autoFocusAgainLater();
}
}
}
}
synchronized void cancelOutstandingTask() {
if (outstandingTask != null) {
if (outstandingTask.getStatus() != AsyncTask.Status.FINISHED) {
outstandingTask.cancel(true);
}
outstandingTask = null;
}
}
public synchronized void stop() {
stopped = true;
if (useAutoFocus) {
cancelOutstandingTask();
// Doesn't hurt to call this even if not focusing
try {
camera.cancelAutoFocus();
} catch (RuntimeException re) {
// Have heard RuntimeException reported in Android 4.0.x+;
// continue?
Log.w(TAG, "Unexpected exception while cancelling focusing", re);
}
}
}
final class AutoFocusTask extends AsyncTask<Object, Object, Object> {
@Override
protected Object doInBackground(Object... voids) {
try {
Thread.sleep(AUTO_FOCUS_INTERVAL_MS);
} catch (InterruptedException e) {
// continue
}
start();
return null;
}
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/camera/CameraConfigurationManager.java
================================================
/*
* 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.liang.scancode.zxing.camera;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Point;
import android.hardware.Camera;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
/**
*
* 邮箱: 1076559197@qq.com | tauchen1990@gmail.com
*
* 作者: 陈涛
*
* 日期: 2014年8月20日
*
* 描述: 该类主要负责设置相机的参数信息,获取最佳的预览界面
*
*/
public final class CameraConfigurationManager {
static final String TAG = "CameraConfiguration";
static final int MIN_PREVIEW_PIXELS = 480 * 320;
static final double MAX_ASPECT_DISTORTION = 0.15;
final Context context;
// 屏幕分辨率
Point screenResolution;
// 相机分辨率
Point cameraResolution;
public CameraConfigurationManager(Context context) {
this.context = context;
}
public void initFromCameraParameters(Camera camera) {
Camera.Parameters parameters = camera.getParameters();
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
Point theScreenResolution = new Point();
theScreenResolution = getDisplaySize(display);
screenResolution = theScreenResolution;
Log.i(TAG, "Screen resolution: " + screenResolution);
/** 因为换成了竖屏显示,所以不替换屏幕宽高得出的预览图是变形的 */
Point screenResolutionForCamera = new Point();
screenResolutionForCamera.x = screenResolution.x;
screenResolutionForCamera.y = screenResolution.y;
if (screenResolution.x < screenResolution.y) {
screenResolutionForCamera.x = screenResolution.y;
screenResolutionForCamera.y = screenResolution.x;
}
cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera);
Log.i(TAG, "Camera resolution x: " + cameraResolution.x);
Log.i(TAG, "Camera resolution y: " + cameraResolution.y);
}
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
Point getDisplaySize(final Display display) {
final Point point = new Point();
try {
display.getSize(point);
} catch (NoSuchMethodError ignore) {
point.x = display.getWidth();
point.y = display.getHeight();
}
return point;
}
public void setDesiredCameraParameters(Camera camera, boolean safeMode) {
Camera.Parameters parameters = camera.getParameters();
if (parameters == null) {
Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
return;
}
Log.i(TAG, "Initial camera parameters: " + parameters.flatten());
if (safeMode) {
Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
}
parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
camera.setParameters(parameters);
Camera.Parameters afterParameters = camera.getParameters();
Camera.Size afterSize = afterParameters.getPreviewSize();
if (afterSize != null && (cameraResolution.x != afterSize.width || cameraResolution.y != afterSize.height)) {
Log.w(TAG, "Camera said it supported preview size " + cameraResolution.x + 'x' + cameraResolution.y + ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
cameraResolution.x = afterSize.width;
cameraResolution.y = afterSize.height;
}
/** 设置相机预览为竖屏 */
camera.setDisplayOrientation(90);
}
public Point getCameraResolution() {
return cameraResolution;
}
public Point getScreenResolution() {
return screenResolution;
}
/**
* 从相机支持的分辨率中计算出最适合的预览界面尺寸
*
* @param parameters
* @param screenResolution
* @return
*/
Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) {
List<Camera.Size> rawSupportedSizes = parameters.getSupportedPreviewSizes();
if (rawSupportedSizes == null) {
Log.w(TAG, "Device returned no supported preview sizes; using default");
Camera.Size defaultSize = parameters.getPreviewSize();
return new Point(defaultSize.width, defaultSize.height);
}
// Sort by size, descending
List<Camera.Size> supportedPreviewSizes = new ArrayList<Camera.Size>(rawSupportedSizes);
Collections.sort(supportedPreviewSizes, new Comparator<Camera.Size>() {
@Override
public int compare(Camera.Size a, Camera.Size b) {
int aPixels = a.height * a.width;
int bPixels = b.height * b.width;
if (bPixels < aPixels) {
return -1;
}
if (bPixels > aPixels) {
return 1;
}
return 0;
}
});
if (Log.isLoggable(TAG, Log.INFO)) {
StringBuilder previewSizesString = new StringBuilder();
for (Camera.Size supportedPreviewSize : supportedPreviewSizes) {
previewSizesString.append(supportedPreviewSize.width).append('x').append(supportedPreviewSize.height).append(' ');
}
Log.i(TAG, "Supported preview sizes: " + previewSizesString);
}
double screenAspectRatio = (double) screenResolution.x / (double) screenResolution.y;
// Remove sizes that are unsuitable
Iterator<Camera.Size> it = supportedPreviewSizes.iterator();
while (it.hasNext()) {
Camera.Size supportedPreviewSize = it.next();
int realWidth = supportedPreviewSize.width;
int realHeight = supportedPreviewSize.height;
if (realWidth * realHeight < MIN_PREVIEW_PIXELS) {
it.remove();
continue;
}
boolean isCandidatePortrait = realWidth < realHeight;
int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth;
int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight;
double aspectRatio = (double) maybeFlippedWidth / (double) maybeFlippedHeight;
double distortion = Math.abs(aspectRatio - screenAspectRatio);
if (distortion > MAX_ASPECT_DISTORTION) {
it.remove();
continue;
}
if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) {
Point exactPoint = new Point(realWidth, realHeight);
Log.i(TAG, "Found preview size exactly matching screen size: " + exactPoint);
return exactPoint;
}
}
// If no exact match, use largest preview size. This was not a great
// idea on older devices because
// of the additional computation needed. We're likely to get here on
// newer Android 4+ devices, where
// the CPU is much more powerful.
if (!supportedPreviewSizes.isEmpty()) {
Camera.Size largestPreview = supportedPreviewSizes.get(0);
Point largestSize = new Point(largestPreview.width, largestPreview.height);
Log.i(TAG, "Using largest suitable preview size: " + largestSize);
return largestSize;
}
// If there is nothing at shouquan_ic_all suitable, return current preview size
Camera.Size defaultPreview = parameters.getPreviewSize();
Point defaultSize = new Point(defaultPreview.width, defaultPreview.height);
Log.i(TAG, "No suitable preview sizes, using default: " + defaultSize);
return defaultSize;
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/camera/CameraManager.java
================================================
/*
* 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.liang.scancode.zxing.camera;
import android.content.Context;
import android.graphics.Point;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
import android.os.Handler;
import android.util.Log;
import android.view.SurfaceHolder;
import java.io.IOException;
import com.liang.scancode.zxing.camera.open.OpenCameraInterface;
/**
* This object wraps the Camera service object and expects to be the only one
* talking to it. The implementation encapsulates the steps needed to take
* preview-sized images, which are used for both preview and decoding.
*
* @author dswitkin@google.com (Daniel Switkin)
*/
public class CameraManager {
static final String TAG = CameraManager.class.getSimpleName();
final Context context;
final CameraConfigurationManager configManager;
Camera camera;
AutoFocusManager autoFocusManager;
boolean initialized;
boolean previewing;
int requestedCameraId = -1;
/**
* Preview frames are delivered here, which we pass on to the registered
* handler. Make sure to clear the handler so it will only receive one
* message.
*/
final PreviewCallback previewCallback;
public CameraManager(Context context) {
this.context = context;
this.configManager = new CameraConfigurationManager(context);
previewCallback = new PreviewCallback(configManager);
}
/**
* Opens the camera driver and initializes the hardware parameters.
*
* @param holder
* The surface object which the camera will draw preview frames
* into.
* @throws IOException
* Indicates the camera driver failed to open.
*/
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
Camera theCamera = camera;
if (theCamera == null) {
if (requestedCameraId >= 0) {
theCamera = OpenCameraInterface.open(requestedCameraId);
} else {
theCamera = OpenCameraInterface.open();
}
if (theCamera == null) {
throw new IOException();
}
camera = theCamera;
}
theCamera.setPreviewDisplay(holder);
if (!initialized) {
initialized = true;
configManager.initFromCameraParameters(theCamera);
}
Parameters parameters = theCamera.getParameters();
String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save
// these,
// temporarily
try {
configManager.setDesiredCameraParameters(theCamera, false);
} catch (RuntimeException re) {
// Driver failed
Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
// Reset:
if (parametersFlattened != null) {
parameters = theCamera.getParameters();
parameters.unflatten(parametersFlattened);
try {
theCamera.setParameters(parameters);
configManager.setDesiredCameraParameters(theCamera, true);
} catch (RuntimeException re2) {
// Well, darn. Give up
Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
}
}
}
}
public synchronized boolean isOpen() {
return camera != null;
}
/**
* Closes the camera driver if still in use.
*/
public synchronized void closeDriver() {
if (camera != null) {
camera.release();
camera = null;
// Make sure to clear these each time we close the camera, so that
// any scanning rect
// requested by intent is forgotten.
}
}
/**
* Asks the camera hardware to begin drawing preview frames to the screen.
*/
public synchronized void startPreview() {
Camera theCamera = camera;
if (theCamera != null && !previewing) {
theCamera.startPreview();
previewing = true;
autoFocusManager = new AutoFocusManager(context, camera);
}
}
/**
* Tells the camera to stop drawing preview frames.
*/
public synchronized void stopPreview() {
if (autoFocusManager != null) {
autoFocusManager.stop();
autoFocusManager = null;
}
if (camera != null && previewing) {
camera.stopPreview();
previewCallback.setHandler(null, 0);
previewing = false;
}
}
/**
* A single preview frame will be returned to the handler supplied. The data
* will arrive as byte[] in the message.obj field, with width and height
* encoded as message.arg1 and message.arg2, respectively.
*
* @param handler
* The handler to send the message to.
* @param message
* The what field of the message to be sent.
*/
public synchronized void requestPreviewFrame(Handler handler, int message) {
Camera theCamera = camera;
if (theCamera != null && previewing) {
previewCallback.setHandler(handler, message);
theCamera.setOneShotPreviewCallback(previewCallback);
}
}
/**
* Allows third party apps to specify the camera ID, rather than determine
* it automatically based on available cameras and their orientation.
*
* @param cameraId
* camera ID of the camera to use. A negative value means
* "no preference".
*/
public synchronized void setManualCameraId(int cameraId) {
requestedCameraId = cameraId;
}
/**
* 获取相机分辨率
*
* @return
*/
public Point getCameraResolution() {
return configManager.getCameraResolution();
}
public Size getPreviewSize() {
if (null != camera) {
return camera.getParameters().getPreviewSize();
}
return null;
}
/**
* 打开闪光灯
*/
public void openLight() {
if (camera != null) {
Parameters parameter = camera.getParameters();
parameter.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameter);
}
}
/**
* 关闭闪光灯
*/
public void offLight() {
if (camera != null) {
Parameters parameter = camera.getParameters();
parameter.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(parameter);
}
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/camera/PreviewCallback.java
================================================
/*
* Copyright (C) 2010 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.liang.scancode.zxing.camera;
import android.graphics.Point;
import android.hardware.Camera;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
public class PreviewCallback implements Camera.PreviewCallback {
static final String TAG = PreviewCallback.class.getSimpleName();
final CameraConfigurationManager configManager;
Handler previewHandler;
int previewMessage;
public PreviewCallback(CameraConfigurationManager configManager) {
this.configManager = configManager;
}
public void setHandler(Handler previewHandler, int previewMessage) {
this.previewHandler = previewHandler;
this.previewMessage = previewMessage;
}
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Point cameraResolution = configManager.getCameraResolution();
Handler thePreviewHandler = previewHandler;
if (cameraResolution != null && thePreviewHandler != null) {
Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x, cameraResolution.y, data);
message.sendToTarget();
previewHandler = null;
} else {
Log.d(TAG, "Got preview callback, but no handler or resolution available");
}
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/camera/open/OpenCameraInterface.java
================================================
/*
* Copyright (C) 2012 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.liang.scancode.zxing.camera.open;
import android.hardware.Camera;
import android.util.Log;
public class OpenCameraInterface {
static final String TAG = OpenCameraInterface.class.getName();
/**
* Opens the requested camera with {@link Camera#open(int)}, if one exists.
*
* @param cameraId
* camera ID of the camera to use. A negative value means
* "no preference"
* @return handle to {@link Camera} that was opened
*/
public static Camera open(int cameraId) {
int numCameras = Camera.getNumberOfCameras();
if (numCameras == 0) {
Log.w(TAG, "No cameras!");
return null;
}
boolean explicitRequest = cameraId >= 0;
if (!explicitRequest) {
// Select a camera if no explicit camera requested
int index = 0;
while (index < numCameras) {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(index, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
break;
}
index++;
}
cameraId = index;
}
Camera camera;
if (cameraId < numCameras) {
Log.i(TAG, "Opening camera #" + cameraId);
camera = Camera.open(cameraId);
} else {
if (explicitRequest) {
Log.w(TAG, "Requested camera does not exist: " + cameraId);
camera = null;
} else {
Log.i(TAG, "No camera facing back; returning camera #0");
camera = Camera.open(0);
}
}
return camera;
}
/**
* Opens a rear-facing camera with {@link Camera#open(int)}, if one exists,
* or opens camera 0.
*
* @return handle to {@link Camera} that was opened
*/
public static Camera open() {
return open(-1);
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/decode/DecodeFormatManager.java
================================================
/*
* Copyright (C) 2010 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.liang.scancode.zxing.decode;
import com.google.zxing.BarcodeFormat;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Set;
public class DecodeFormatManager {
// 1D解码
static final Set<BarcodeFormat> PRODUCT_FORMATS;
static final Set<BarcodeFormat> INDUSTRIAL_FORMATS;
static final Set<BarcodeFormat> ONE_D_FORMATS;
// 二维码解码
static final Set<BarcodeFormat> QR_CODE_FORMATS;
static {
PRODUCT_FORMATS = EnumSet.of(BarcodeFormat.UPC_A, BarcodeFormat.UPC_E, BarcodeFormat.EAN_13, BarcodeFormat.EAN_8, BarcodeFormat.RSS_14, BarcodeFormat.RSS_EXPANDED);
INDUSTRIAL_FORMATS = EnumSet.of(BarcodeFormat.CODE_39, BarcodeFormat.CODE_93, BarcodeFormat.CODE_128, BarcodeFormat.ITF, BarcodeFormat.CODABAR);
ONE_D_FORMATS = EnumSet.copyOf(PRODUCT_FORMATS);
ONE_D_FORMATS.addAll(INDUSTRIAL_FORMATS);
QR_CODE_FORMATS = EnumSet.of(BarcodeFormat.QR_CODE);
}
public static Collection<BarcodeFormat> getQrCodeFormats() {
return QR_CODE_FORMATS;
}
public static Collection<BarcodeFormat> getBarCodeFormats() {
return ONE_D_FORMATS;
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/decode/DecodeHandler.java
================================================
/*
* Copyright (C) 2010 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.liang.scancode.zxing.decode;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.hardware.Camera.Size;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.PlanarYUVLuminanceSource;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.common.HybridBinarizer;
import com.liang.scancode.R;
import com.liang.scancode.zxing.ScanManager;
import java.io.ByteArrayOutputStream;
import java.util.Map;
public class DecodeHandler extends Handler {
final ScanManager scanManager;
final MultiFormatReader multiFormatReader;
boolean running = true;
public DecodeHandler(ScanManager scanManager, Map<DecodeHintType, Object> hints) {
multiFormatReader = new MultiFormatReader();
multiFormatReader.setHints(hints);
this.scanManager = scanManager;
}
@Override
public void handleMessage(Message message) {
if (!running) {
return;
}
switch (message.what) {
case R.id.decode:
decode((byte[]) message.obj, message.arg1, message.arg2);
break;
case R.id.quit:
running = false;
Looper.myLooper().quit();
break;
}
}
/**
* Decode the data within the viewfinder rectangle, and time how long it
* took. For efficiency, reuse the same reader objects from one decode to
* the next.
*
* @param data
* The YUV preview frame.
* @param width
* The width of the preview frame.
* @param height
* The height of the preview frame.
*/
void decode(byte[] data, int width, int height) {
Size size = scanManager.getCameraManager().getPreviewSize();
// 这里需要将获取的data翻转一下,因为相机默认拿的的横屏的数据
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < size.height; y++) {
for (int x = 0; x < size.width; x++)
rotatedData[x * size.height + size.height - y - 1] = data[x + y * size.width];
}
// 宽高也要调整
int tmp = size.width;
size.width = size.height;
size.height = tmp;
Result rawResult = null;
PlanarYUVLuminanceSource source = buildLuminanceSource(rotatedData, size.width, size.height);
if (source != null) {
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (ReaderException re) {
// continue
} finally {
multiFormatReader.reset();
}
}
Handler handler = scanManager.getHandler();
if (rawResult != null) {
// Don't log the barcode contents for security.
if (handler != null) {
Message message = Message.obtain(handler, R.id.decode_succeeded, rawResult);
Bundle bundle = new Bundle();
bundleThumbnail(source, bundle);
message.setData(bundle);
message.sendToTarget();
}
} else {
if (handler != null) {
Message message = Message.obtain(handler, R.id.decode_failed);
message.sendToTarget();
}
}
}
static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
int[] pixels = source.renderThumbnail();
int width = source.getThumbnailWidth();
int height = source.getThumbnailHeight();
Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
}
/**
* A factory method to build the appropriate LuminanceSource object based on
* the format of the preview buffers, as described by Camera.Parameters.
*
* @param data
* A preview frame.
* @param width
* The width of the image.
* @param height
* The height of the image.
* @return A PlanarYUVLuminanceSource instance.
*/
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
Rect rect = scanManager.getCropRect();
if (rect == null) {
return null;
}
// Go ahead and assume it's YUV rather than die.
return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect.height(), false);
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/decode/DecodeThread.java
================================================
/*
* 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.liang.scancode.zxing.decode;
import android.os.Handler;
import android.os.Looper;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import com.liang.scancode.zxing.ScanManager;
/**
* This thread does shouquan_ic_all the heavy lifting of decoding the images.
*
* @author dswitkin@google.com (Daniel Switkin)
*/
public class DecodeThread extends Thread {
public static final String BARCODE_BITMAP = "barcode_bitmap";
public static final int BARCODE_MODE = 0X100;
public static final int QRCODE_MODE = 0X200;
public static final int ALL_MODE = 0X300;
final ScanManager scanManager;
static Map<DecodeHintType, Object> hints;
Handler handler;
final CountDownLatch handlerInitLatch;
public DecodeThread(ScanManager scanManager, int decodeMode) {
this.scanManager = scanManager;
handlerInitLatch = new CountDownLatch(1);
hints = new EnumMap<DecodeHintType, Object>(DecodeHintType.class);
Collection<BarcodeFormat> decodeFormats = new ArrayList<BarcodeFormat>();
decodeFormats.addAll(EnumSet.of(BarcodeFormat.AZTEC));
decodeFormats.addAll(EnumSet.of(BarcodeFormat.PDF_417));
switch (decodeMode) {
case BARCODE_MODE:
decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats());
break;
case QRCODE_MODE:
decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats());
break;
case ALL_MODE:
decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats());
decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats());
break;
default:
break;
}
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
}
public Handler getHandler() {
try {
handlerInitLatch.await();
} catch (InterruptedException ie) {
// continue?
}
return handler;
}
@Override
public void run() {
Looper.prepare();
handler = new DecodeHandler(scanManager, hints);
handlerInitLatch.countDown();
Looper.loop();
}
public static Map<DecodeHintType, Object> getHints() {
return hints;
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/decode/PhotoScanHandler.java
================================================
package com.liang.scancode.zxing.decode;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import com.google.zxing.Result;
import com.liang.scancode.zxing.ScanManager;
public class PhotoScanHandler extends Handler{
public final static int PHOTODECODEERROR=0;
public final static int PHOTODECODEOK=1;
ScanManager scanManager;
public PhotoScanHandler(ScanManager scanManager) {
this.scanManager=scanManager;
}
@Override
public void handleMessage(Message message) {
switch (message.what) {
case PHOTODECODEERROR:
scanManager.handleDecodeError((Exception)message.obj);
break;
case PHOTODECODEOK:
Bundle bundle = message.getData();
scanManager.handleDecode((Result) message.obj, bundle);
break;
default:
break;
}
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/decode/RGBLuminanceSource.java
================================================
package com.liang.scancode.zxing.decode;
/*
* Copyright 2009 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.
*/
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.google.zxing.LuminanceSource;
import java.io.FileNotFoundException;
/**
* This class is used to help decode images from files which arrive as RGB data
* from Android bitmaps. It does not support cropping or rotation.
*
* @author dswitkin@google.com (Daniel Switkin)
*/
public final class RGBLuminanceSource extends LuminanceSource {
final byte[] luminances;
public RGBLuminanceSource(String path) throws FileNotFoundException {
this(loadBitmap(path));
}
public RGBLuminanceSource(Bitmap bitmap) {
super(bitmap.getWidth(), bitmap.getHeight());
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
// In order to measure pure decoding speed, we convert the entire image
// to a greyscale array
// up front, which is the same as the Y channel of the
// YUVLuminanceSource in the real app.
luminances = new byte[width * height];
for (int y = 0; y < height; y++) {
int offset = y * width;
for (int x = 0; x < width; x++) {
int pixel = pixels[offset + x];
int r = (pixel >> 16) & 0xff;
int g = (pixel >> 8) & 0xff;
int b = pixel & 0xff;
if (r == g && g == b) {
// Image is already greyscale, so pick any channel.
luminances[offset + x] = (byte) r;
} else {
// Calculate luminance cheaply, favoring green.
luminances[offset + x] = (byte) ((r + g + g + b) >> 2);
}
}
}
}
@Override
public byte[] getRow(int y, byte[] row) {
if (y < 0 || y >= getHeight()) {
throw new IllegalArgumentException(
"Requested row is outside the image: " + y);
}
int width = getWidth();
if (row == null || row.length < width) {
row = new byte[width];
}
System.arraycopy(luminances, y * width, row, 0, width);
return row;
}
// Since this class does not support cropping, the underlying byte array
// already contains
// exactly what the caller is asking for, so give it to them without a copy.
@Override
public byte[] getMatrix() {
return luminances;
}
static Bitmap loadBitmap(String path) throws FileNotFoundException {
Bitmap bitmap = BitmapFactory.decodeFile(path);
if (bitmap == null) {
throw new FileNotFoundException("Couldn't open " + path);
}
return bitmap;
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/decode/Utils.java
================================================
package com.liang.scancode.zxing.decode;
import android.annotation.SuppressLint;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import java.io.IOException;
public class Utils {
@SuppressLint("NewApi")
public static String getPath(final Context context, final Uri uri) {
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/"
+ split[1];
}
// TODO handle non-primary volumes
}
// DownloadsProvider
else if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"),
Long.valueOf(id));
return getDataColumn(context, contentUri, null, null);
}
// MediaProvider
else if (isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = "_id=?";
final String[] selectionArgs = new String[]{split[1]};
return getDataColumn(context, contentUri, selection,
selectionArgs);
}
}
// MediaStore (and general)
else if ("content".equalsIgnoreCase(uri.getScheme())) {
return getDataColumn(context, uri, null, null);
}
// File
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}
public static String getDataColumn(Context context, Uri uri,
String selection, String[] selectionArgs) {
Cursor cursor = null;
final String column = "_data";
final String[] projection = {column};
try {
cursor = context.getContentResolver().query(uri, projection,
selection, selectionArgs, null);
if (cursor != null && cursor.moveToFirst()) {
final int column_index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(column_index);
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
public static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri
.getAuthority());
}
public static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri
.getAuthority());
}
public static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri
.getAuthority());
}
/**
* 读取图片属性:旋转的角度
* @param path 图片绝对路径
* @return degree旋转的角度
*/
public static int readPictureDegree(String path) {
int degree = 0;
try {
ExifInterface exifInterface = new ExifInterface(path);
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
degree = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
degree = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
degree = 270;
break;
}
} catch (IOException e) {
e.printStackTrace();
}
return degree;
}
/*
* 旋转图片
* @param angle
* @param bitmap
* @return Bitmap
*/
public static Bitmap rotaingImageView(int angle , Bitmap bitmap) {
//旋转图片 动作
Matrix matrix = new Matrix();;
matrix.postRotate(angle);
System.out.println("angle2=" + angle);
// 创建新的图片
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
return resizedBitmap;
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/encode/EncodingHandler.java
================================================
package com.liang.scancode.zxing.encode;
import android.graphics.Bitmap;
import android.util.Log;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import java.io.UnsupportedEncodingException;
import java.util.Hashtable;
/**
* @author 刘红亮 2015年4月29日 下午3:27:08
* 用于生成二维码
*/
public final class EncodingHandler {
static final int BLACK = 0xff000000;
static final int WHITE = 0xFFFFFFFF;
/**
* 生成二维码图片
*
* @param str 要往二维码中写入的内容,需要utf-8格式
* @param widthAndHeight 图片的宽高,正方形
* @return 返回一个二维码bitmap
* @throws WriterException
* @throws UnsupportedEncodingException
*/
public static Bitmap create2Code(String str, int widthAndHeight) throws WriterException, UnsupportedEncodingException {
BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight, getEncodeHintMap());
return BitMatrixToBitmap(matrix);
}
/**
* 生成条形码图片
* @param str 要往二维码中写入的内容,需要utf-8格式
* @param width 图片的宽
* @param height 图片的高
* @return 返回一个条形bitmap
* @throws Exception
*/
public static Bitmap createBarCode(String str, Integer width, Integer height) throws Exception{
BitMatrix bitMatrix = new MultiFormatWriter().encode(str, BarcodeFormat.CODE_128, width, height, getEncodeHintMap());
return BitMatrixToBitmap(bitMatrix);
}
/**
* 获得设置好的编码参数
* @return 编码参数
*/
private static Hashtable<EncodeHintType, Object> getEncodeHintMap() {
Hashtable<EncodeHintType, Object> hints= new Hashtable<EncodeHintType, Object>();
//设置编码为utf-8
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
// 设置QR二维码的纠错级别——这里选择最高H级别
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
return hints;
}
/**
* BitMatrix转换成Bitmap
*
* @param matrix
* @return
*/
private static Bitmap BitMatrixToBitmap(BitMatrix matrix) {
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
int offset = y * width;
for (int x = 0; x < width; x++) {
if(matrix.get(x,y)){
pixels[offset + x] =BLACK; //上面图案的颜色
}else{
pixels[offset + x] =WHITE;//底色
}
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
Log.e("hongliang","width:"+bitmap.getWidth()+" height:"+bitmap.getHeight());
return bitmap;
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/utils/AppliationUtil.java
================================================
package com.liang.scancode.zxing.utils;
/**
* Created by 刘红亮 on 2015/7/23 22:35.
*/
public class AppliationUtil {
//应用程序最大可用内存
public static int MAX_MEMORY = ((int) Runtime.getRuntime().maxMemory())/1024/1024;
//应用程序已获得内存
public static long TOTAL_MEMORY = ((int) Runtime.getRuntime().totalMemory())/1024/1024;
//应用程序已获得内存中未使用内存
public static long FREE_MEMORY = ((int) Runtime.getRuntime().freeMemory())/1024/1024;
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/utils/BeepManager.java
================================================
/*
* Copyright (C) 2010 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.liang.scancode.zxing.utils;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.AssetFileDescriptor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.util.Log;
import com.liang.scancode.R;
import java.io.Closeable;
import java.io.IOException;
/**
*/
public class BeepManager implements MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, Closeable {
static final String TAG = BeepManager.class.getSimpleName();
static final float BEEP_VOLUME = 0.10f;
static final long VIBRATE_DURATION = 200L;
final Activity activity;
MediaPlayer mediaPlayer;
boolean playBeep;
boolean vibrate;
public BeepManager(Activity activity) {
this.activity = activity;
this.mediaPlayer = null;
updatePrefs();
}
synchronized void updatePrefs() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
playBeep = shouldBeep(prefs, activity);
vibrate = true;
if (playBeep && mediaPlayer == null) {
// The volume on STREAM_SYSTEM is not adjustable, and users found it
// too loud,
// so we now play on the music stream.
activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = buildMediaPlayer(activity);
}
}
public synchronized void playBeepSoundAndVibrate() {
if (playBeep && mediaPlayer != null) {
mediaPlayer.start();
}
if (vibrate) {
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATE_DURATION);
}
}
static boolean shouldBeep(SharedPreferences prefs, Context activity) {
boolean shouldPlayBeep = true;
if (shouldPlayBeep) {
// See if sound settings overrides this
AudioManager audioService = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
shouldPlayBeep = false;
}
}
return shouldPlayBeep;
}
MediaPlayer buildMediaPlayer(Context activity) {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setOnErrorListener(this);
try {
AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
} finally {
file.close();
}
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
return mediaPlayer;
} catch (IOException ioe) {
Log.w(TAG, ioe);
mediaPlayer.release();
return null;
}
}
@Override
public void onCompletion(MediaPlayer mp) {
// When the beep has finished playing, rewind to queue up another one.
mp.seekTo(0);
}
@Override
public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
// we are finished, so put up an appropriate error toast if required
// and finish
activity.finish();
} else {
// possibly media player error, so release and recreate
mp.release();
mediaPlayer = null;
updatePrefs();
}
return true;
}
@Override
public synchronized void close() {
if (mediaPlayer != null) {
mediaPlayer.release();
mediaPlayer = null;
}
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/utils/BitmapUtil.java
================================================
package com.liang.scancode.zxing.utils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
/**
* Created by 刘红亮 on 2015/7/23 22:30.
*/
public class BitmapUtil {
/**
*
* @param options
* @param reqWidth
* @param reqHeight
* @return
*/
public static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
// 源图片的高度和宽度
final int height = options.outHeight;
final int width = options.outWidth;
//压缩当前图片占用内存不超过应用可用内存的3/4
//ARGB_8888 一个像素占用4个字节
//1兆字节(mb)=1048576字节(b)
while(reqHeight*reqWidth*4> AppliationUtil.FREE_MEMORY*1048576/4*3){
reqHeight-=50;
reqWidth-=50;
}
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
// 计算出实际宽高和目标宽高的比率
final int heightRatio = Math.round((float) height / (float) reqHeight);
final int widthRatio = Math.round((float) width / (float) reqWidth);
// 选择宽和高中最小的比率作为inSampleSize的值,这样可以保证最终图片的宽和高
// 一定都会大于等于目标的宽和高。
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
if(inSampleSize==0) return 1;
Log.e("hongliang","inSampleSize=" + inSampleSize);
return inSampleSize;
}
public static Bitmap decodeBitmapFromPath(String photo_path, int reqWidth, int reqHeight) {
// 第一次解析将inJustDecodeBounds设置为true,来获取图片大小
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Bitmap scanBitmap = BitmapFactory.decodeFile(photo_path, options);
// 调用上面定义的方法计算inSampleSize值
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// 使用获取到的inSampleSize值再次解析图片
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(photo_path, options);
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/utils/CaptureActivityHandler.java
================================================
/*
* 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.liang.scancode.zxing.utils;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import com.google.zxing.Result;
import com.liang.scancode.R;
import com.liang.scancode.zxing.ScanManager;
import com.liang.scancode.zxing.camera.CameraManager;
import com.liang.scancode.zxing.decode.DecodeThread;
/**
* This class handles shouquan_ic_all the messaging which comprises the state machine for
* capture.
*
* @author dswitkin@google.com (Daniel Switkin)
*/
public class CaptureActivityHandler extends Handler {
final ScanManager scanManager;
final DecodeThread decodeThread;
final CameraManager cameraManager;
State state;
enum State {
PREVIEW, SUCCESS, DONE
}
public CaptureActivityHandler(ScanManager scanManager, CameraManager cameraManager, int decodeMode) {
this.scanManager = scanManager;
decodeThread = new DecodeThread(scanManager, decodeMode);
decodeThread.start();
state = State.SUCCESS;
// Start ourselves capturing previews and decoding.
this.cameraManager = cameraManager;
cameraManager.startPreview();
restartPreviewAndDecode();
}
@Override
public void handleMessage(Message message) {
switch (message.what) {
case R.id.restart_preview:
restartPreviewAndDecode();
break;
case R.id.decode_succeeded:
state = State.SUCCESS;
Bundle bundle = message.getData();
scanManager.handleDecode((Result) message.obj, bundle);
break;
case R.id.decode_failed:
// We're decoding as fast as possible, so when one decode fails,
// start another.
state = State.PREVIEW;
cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
break;
case R.id.decode_error:
scanManager.handleDecodeError((Exception)message.obj);
break;
case R.id.return_scan_result:
// activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
// activity.finish();
break;
}
}
public void quitSynchronously() {
state = State.DONE;
cameraManager.stopPreview();
Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit);
quit.sendToTarget();
try {
// Wait at most half a shouquan_icon_second; should be enough time, and onPause()
// will timeout quickly
decodeThread.join(500L);
} catch (InterruptedException e) {
// continue
}
// Be absolutely sure we don't send any queued up messages
removeMessages(R.id.decode_succeeded);
removeMessages(R.id.decode_failed);
}
void restartPreviewAndDecode() {
if (state == State.SUCCESS) {
state = State.PREVIEW;
cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
}
}
/**
*
* @return 返回当前扫描状态,是否可扫描,State.PREVIEW 是可扫描状态
*/
public boolean isScanning() {
if(state == State.PREVIEW){
return true;
}
return false;
}
}
================================================
FILE: app/src/main/java/com/liang/scancode/zxing/utils/InactivityTimer.java
================================================
/*
* Copyright (C) 2010 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.liang.scancode.zxing.utils;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncTask;
import android.os.BatteryManager;
import android.os.Build;
import android.util.Log;
/**
* Finishes an activity after a period of inactivity if the device is on battery
* power.
*/
public class InactivityTimer {
static final String TAG = InactivityTimer.class.getSimpleName();
static final long INACTIVITY_DELAY_MS = 5 * 60 * 1000L;
Activity activity;
BroadcastReceiver powerStatusReceiver;
boolean registered;
AsyncTask<Object, Object, Object> inactivityTask;
public InactivityTimer(Activity activity) {
this.activity = activity;
powerStatusReceiver = new PowerStatusReceiver();
registered = false;
onActivity();
}
@SuppressLint("NewApi")
public synchronized void onActivity() {
cancel();
inactivityTask = new InactivityAsyncTask();
if (Build.VERSION.SDK_INT >= 11) {
inactivityTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
inactivityTask.execute();
}
}
public synchronized void onPause() {
cancel();
if (registered) {
activity.unregisterReceiver(powerStatusReceiver);
registered = false;
} else {
Log.w(TAG, "PowerStatusReceiver was never registered?");
}
}
public synchronized void onResume() {
if (registered) {
Log.w(TAG, "PowerStatusReceiver was already registered?");
} else {
activity.registerReceiver(powerStatusReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
registered = true;
}
onActivity();
}
synchronized void cancel() {
AsyncTask<?, ?, ?> task = inactivityTask;
if (task != null) {
task.cancel(true);
inactivityTask = null;
}
}
public void shutdown() {
cancel();
}
class PowerStatusReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
// 0 indicates that we're on battery
boolean onBatteryNow = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) <= 0;
if (onBatteryNow) {
InactivityTimer.this.onActivity();
} else {
InactivityTimer.this.cancel();
}
}
}
}
class InactivityAsyncTask extends AsyncTask<Object, Object, Object> {
@Override
protected Object doInBackground(Object... objects) {
try {
Thread.sleep(INACTIVITY_DELAY_MS);
Log.i(TAG, "Finishing activity due to inactivity");
activity.finish();
} catch (InterruptedException e) {
// continue without killing
}
return null;
}
}
}
================================================
FILE: app/src/main/res/anim/popupwin_nearperson_exit.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate
android:fromYDelta="0"
android:toYDelta="100%"
android:duration="250"
/>
</set>
================================================
FILE: app/src/main/res/anim/popupwin_nearperson_show.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate
android:fromYDelta="100%"
android:toYDelta="0"
android:duration="250"
/>
</set>
================================================
FILE: app/src/main/res/anim/shouquan_dialog_enter.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- from从始点开始动画 -->
<translate android:duration="300" android:fromYDelta="100%p" />
</set>
================================================
FILE: app/src/main/res/anim/shouquan_dialog_exit.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- to从终点技术动画 -->
<translate android:duration="300" android:toYDelta="100%p"/>
</set>
================================================
FILE: app/src/main/res/drawable/base_bgpic.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
><!-- android:shape="" 表示是圆角矩形还是椭圆等等 -->
<solid android:color="#FFFFFF"/> <!-- 背景颜色 -->
<!-- padding 表示内部空间距离背景图片内部边距 的距离 -->
<!--<padding android:left="5dp" android:top="5dp"-->
<!--android:right="5dp" android:bottom="5dp" />-->
<stroke android:width="0.5dp" android:color="#D9D9D9"/> <!-- 图片边框属性 -->
<corners android:radius="5dp" /> <!-- 圆角的程度 -->
<gradient android:startColor="#FFFFFF" android:centerColor="#FFFFFF"
android:endColor="#FFFFFF" android:type="linear" android:angle="90"
android:centerX="0.5" android:centerY="0.5" />
</shape>
================================================
FILE: app/src/main/res/drawable/rescan_shape_button.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- 背景颜色 -->
<solid android:color="#ff6a62"/>
<!-- 圆角的程度 -->
<corners android:radius="4dp" />
<!-- 矩形的边线 -->
<stroke
android:width="1dp" />
</shape>
================================================
FILE: app/src/main/res/drawable/shouquan_bg_loading_dialog_shape.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="10dp"/>
<solid android:color="@android:color/white"/>
</shape>
================================================
FILE: app/src/main/res/drawable/shouquan_loading_dialog_progressbar.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/shouquan_iloading_progress"
android:pivotX="50%"
android:pivotY="50%" />
================================================
FILE: app/src/main/res/drawable/shouquan_qrcode_g_gallery.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/scan2code_icon_xiangce" android:state_pressed="true"/>
<item android:drawable="@drawable/scan2code_icon_xiangce_sel"/>
</selector>
================================================
FILE: app/src/main/res/drawable/shouquan_qrcode_ic_back.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/scan2code_icon_back_sel" android:state_pressed="true" />
<item android:drawable="@drawable/scan2code_icon_back_nor"/>
</selector>
================================================
FILE: app/src/main/res/drawable/shouquan_qrcode_s_flashgun.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/scan2code_icon_light_sel" android:state_pressed="true"/>
<item android:drawable="@drawable/scan2code_icon_light_nor"/>
</selector>
================================================
FILE: app/src/main/res/layout/activity_create_code.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
>
<EditText
android:id="@+id/et_code_key"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="输入要生成码的内容"
android:gravity="center"
android:textSize="17sp"
android:padding="10dp"
android:layout_marginTop="40dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/btn_create_code"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="生成码"
android:gravity="center"
android:textSize="17sp"
/>
<Button
android:id="@+id/btn_create_code_and_img"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="加个头像"
android:gravity="center"
android:textSize="17sp"
/>
</LinearLayout>
<ImageView
android:id="@+id/iv_2_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_light"
/>
<ImageView
android:layout_marginTop="20dp"
android:id="@+id/iv_bar_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
================================================
FILE: app/src/main/res/layout/activity_main.xml
================================================
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="生成二维码/条形码"
android:id="@+id/create_code"
android:gravity="center"
android:padding="10dp"
android:layout_marginTop="50dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="扫描二维码"
android:id="@+id/scan_2code"
android:gravity="center"
android:padding="10dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="扫描条形码"
android:id="@+id/scan_bar_code"
android:gravity="center"
android:padding="10dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="扫描二维码或者条形码"
android:id="@+id/scan_code"
android:gravity="center"
android:padding="10dp"
/>
</LinearLayout>
================================================
FILE: app/src/main/res/layout/activity_scan_code.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/capture_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white" >
<SurfaceView
android:id="@+id/capture_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<!-- 扫描框上面的布局 -->
<RelativeLayout
android:id="@+id/top_mask"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:background="@color/scan_bg">
<RelativeLayout
android:id="@+id/title_bar"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:background="@android:color/white" >
<ImageView
android:id="@+id/authorize_return"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@null"
android:paddingLeft="12dp"
android:paddingRight="20dp"
android:src="@drawable/ic_my_returns_arrow"
/>
<TextView
android:id="@+id/common_title_TV_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ellipsize="middle"
android:singleLine="true"
android:text="二维码扫描"
android:textSize="18sp" />
</RelativeLayout>
<TextView
android:id="@+id/tv_scan_result"
android:layout_marginTop="20dp"
android:layout_below="@id/title_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="哈哈"
android:textSize="14sp"
android:layout_centerInParent="true"
android:textColor="@android:color/white"
android:visibility="gone"
/>
</RelativeLayout>
<!-- 扫描框底部的布局 -->
<RelativeLayout
android:id="@+id/bottom_mask"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:background="@color/scan_bg"
android:orientation="vertical"
android:paddingBottom="16dp"
>
<TextView
android:id="@+id/scan_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/scan_allcode_hint"
android:textColor="#b4b4b4"
android:textSize="14sp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
/>
<TextView
android:id="@+id/iv_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:layout_below="@id/scan_hint"
android:background="@drawable/shouquan_qrcode_s_flashgun"
android:clickable="true" />
<TextView
android:id="@+id/qrcode_ic_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/scan_hint"
android:background="@drawable/shouquan_qrcode_ic_back"
android:clickable="true" />
<TextView
android:id="@+id/qrcode_g_gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="30dp"
android:layout_below="@id/scan_hint"
android:background="@drawable/shouquan_qrcode_g_gallery"
android:clickable="true"
android:textSize="20sp" />
<Button
android:id="@+id/service_register_rescan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/rescan_shape_button"
android:padding="10dp"
android:text="再次扫描"
android:textColor="@android:color/white"
android:textSize="18sp"
android:layout_centerHorizontal="true"
android:layout_below="@id/qrcode_g_gallery"
android:visibility="visible"
android:layout_marginTop="20dp"
/>
</RelativeLayout>
<!-- 扫描框中间的布局 -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/top_mask"
android:layout_above="@id/bottom_mask"
>
<ImageView
android:id="@+id/left_mask"
android:layout_width="34dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="@color/scan_bg"
android:contentDescription="@string/app_name" />
<ImageView
android:id="@+id/right_mask"
android:layout_width="34dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="@color/scan_bg" />
<RelativeLayout
android:id="@+id/capture_crop_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/right_mask"
android:layout_toRightOf="@id/left_mask"
android:layout_centerHorizontal="true"
android:background="@android:color/transparent" >
<ImageView
android:id="@+id/capture_scan_line"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:background="@drawable/scanning_line" />
<com.liang.scancode.defineview.MyImageView
android:id="@+id/scan_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
================================================
FILE: app/src/main/res/layout/activity_scan_result.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="45dip"
android:background="@android:color/white" >
<ImageView
android:id="@+id/authorize_return"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@null"
android:paddingLeft="12dp"
android:paddingRight="20dp"
android:src="@drawable/ic_my_returns_arrow"
/>
<TextView
android:id="@+id/common_title_TV_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ellipsize="middle"
android:singleLine="true"
android:text="扫描结果"
android:textSize="18sp" />
</RelativeLayout>
<TextView
android:id="@+id/tv_scan_result"
android:layout_marginTop="20dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="扫描结果:"
/>
<ImageView
android:id="@+id/iv_scan_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
================================================
FILE: app/src/main/res/menu/menu_jump_to.xml
================================================
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="cn.sibu.plugin.scan2code.JumpToActivity">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" android:showAsAction="never" />
</menu>
================================================
FILE: app/src/main/res/menu/menu_sao_mao.xml
================================================
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="cn.sibu.plugin.scan2code.SaoMaoActivity">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" android:showAsAction="never" />
</menu>
================================================
FILE: app/src/main/res/values/Qrcode_ids.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<resources>
<item name="decode" type="id"/>
<item name="decode_failed" type="id"/>
<item name="decode_succeeded" type="id"/>
<item name="quit" type="id"/>
<item name="restart_preview" type="id"/>
<item name="return_scan_result" type="id"/>
<item name="decode_error" type="id"/>
</resources>
================================================
FILE: app/src/main/res/values/colors.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="scan_bg">#7f000000</color>
</resources>
================================================
FILE: app/src/main/res/values/dimens.xml
================================================
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
================================================
FILE: app/src/main/res/values/strings.xml
================================================
<resources>
<string name="app_name">Scan2Code</string>
<string name="hello_world">Hello world!</string>
<string name="scan_barcode_title">条形码扫描</string>
<string name="scan_qrcode_title">二维码扫描</string>
<string name="scan_allcode_title">二维码或条形码扫描</string>
<string name="scan_barcode_hint">将条形码对入取景框,即可自动扫描</string>
<string name="scan_qrcode_hint">将二维码对入取景框,即可自动扫描</string>
<string name="scan_allcode_hint">将二维码或条形码对入取景框,即可自动扫描</string>
<string name="title_activity_sao_mao">SaoMaoActivity</string>
<string name="action_settings">Settings</string>
<color name="line_color">#cccccc</color>
<color name="edittext_line_color">#000000</color>
<string name="title_activity_jump_to">JumpToActivity</string>
</resources>
================================================
FILE: app/src/main/res/values/styles.xml
================================================
<resources>
<!-- Base application theme. -->
<style name="AppTheme">
<!-- Customize your theme here. -->
</style>
<style name="popwin_nearpenson_anim_style">
<item name="android:windowEnterAnimation">@anim/popupwin_nearperson_show</item>
<item name="android:windowExitAnimation">@anim/popupwin_nearperson_exit</item>
</style>
<!--分割线样式-->
<style name="lineStyle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">0.5dp</item>
<item name="android:background">#cccccc</item>
</style>
<!-- 只有背景的对话框样式 -->
<style name="dialog_show_style" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<!-- 设置dialog的半透明背景的灰度 -->
<item name="android:backgroundDimAmount">0.6</item>
</style>
<style name="my_style">
<item name="android:windowEnterAnimation">@anim/shouquan_dialog_enter</item>
<item name="android:windowExitAnimation">@anim/shouquan_dialog_exit</item>
</style>
</resources>
================================================
FILE: app/src/main/res/values-w820dp/dimens.xml
================================================
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
================================================
FILE: gradle.properties
================================================
## Project-wide Gradle settings.
#
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Mon Aug 17 15:58:13 CST 2015
systemProp.http.proxyHost=hx.gy
systemProp.http.proxyPort=1080
================================================
FILE: gradlew
================================================
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: settings.gradle
================================================
include ':app'
gitextract_qo_l_5id/ ├── .gitignore ├── .idea/ │ ├── .name │ ├── compiler.xml │ ├── copyright/ │ │ └── profiles_settings.xml │ ├── encodings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ ├── runConfigurations.xml │ └── vcs.xml ├── README.md ├── ScanCode.iml ├── app/ │ ├── .gitignore │ ├── app.iml │ ├── build.gradle │ ├── libs/ │ │ ├── butterknife-7.0.1.jar │ │ └── zxing.jar │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── liang/ │ │ └── scancode/ │ │ ├── CommonScanActivity.java │ │ ├── CreateCodeActivity.java │ │ ├── MainActivity.java │ │ ├── defineview/ │ │ │ └── MyImageView.java │ │ ├── utils/ │ │ │ └── Constant.java │ │ └── zxing/ │ │ ├── ScanListener.java │ │ ├── ScanManager.java │ │ ├── camera/ │ │ │ ├── AutoFocusManager.java │ │ │ ├── CameraConfigurationManager.java │ │ │ ├── CameraManager.java │ │ │ ├── PreviewCallback.java │ │ │ └── open/ │ │ │ └── OpenCameraInterface.java │ │ ├── decode/ │ │ │ ├── DecodeFormatManager.java │ │ │ ├── DecodeHandler.java │ │ │ ├── DecodeThread.java │ │ │ ├── PhotoScanHandler.java │ │ │ ├── RGBLuminanceSource.java │ │ │ └── Utils.java │ │ ├── encode/ │ │ │ └── EncodingHandler.java │ │ └── utils/ │ │ ├── AppliationUtil.java │ │ ├── BeepManager.java │ │ ├── BitmapUtil.java │ │ ├── CaptureActivityHandler.java │ │ └── InactivityTimer.java │ └── res/ │ ├── anim/ │ │ ├── popupwin_nearperson_exit.xml │ │ ├── popupwin_nearperson_show.xml │ │ ├── shouquan_dialog_enter.xml │ │ └── shouquan_dialog_exit.xml │ ├── drawable/ │ │ ├── base_bgpic.xml │ │ ├── rescan_shape_button.xml │ │ ├── shouquan_bg_loading_dialog_shape.xml │ │ ├── shouquan_loading_dialog_progressbar.xml │ │ ├── shouquan_qrcode_g_gallery.xml │ │ ├── shouquan_qrcode_ic_back.xml │ │ └── shouquan_qrcode_s_flashgun.xml │ ├── layout/ │ │ ├── activity_create_code.xml │ │ ├── activity_main.xml │ │ ├── activity_scan_code.xml │ │ └── activity_scan_result.xml │ ├── menu/ │ │ ├── menu_jump_to.xml │ │ └── menu_sao_mao.xml │ ├── raw/ │ │ └── beep.ogg │ ├── values/ │ │ ├── Qrcode_ids.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── values-w820dp/ │ └── dimens.xml ├── build.gradle ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat └── settings.gradle
SYMBOL INDEX (157 symbols across 24 files)
FILE: app/src/main/java/com/liang/scancode/CommonScanActivity.java
class CommonScanActivity (line 50) | public final class CommonScanActivity extends Activity implements ScanLi...
method onCreate (line 79) | @Override
method initView (line 91) | void initView() {
method onResume (line 122) | @Override
method onPause (line 130) | @Override
method scanResult (line 138) | public void scanResult(Result rawResult, Bundle bundle) {
method startScan (line 161) | void startScan() {
method scanError (line 169) | @Override
method showPictures (line 178) | public void showPictures(int requestCode) {
method onActivityResult (line 184) | @Override
method onClick (line 205) | @Override
FILE: app/src/main/java/com/liang/scancode/CreateCodeActivity.java
class CreateCodeActivity (line 29) | public class CreateCodeActivity extends Activity {
method onCreate (line 39) | @Override
method clickListener (line 45) | @OnClick({R.id.btn_create_code,R.id.btn_create_code_and_img})
method createBarCode (line 66) | private Bitmap createBarCode(String key) {
method create2Code (line 82) | private Bitmap create2Code(String key) {
method getHeadBitmap (line 97) | private Bitmap getHeadBitmap(int size) {
method createQRCodeBitmapWithPortrait (line 116) | private void createQRCodeBitmapWithPortrait(Bitmap qr, Bitmap portrait) {
FILE: app/src/main/java/com/liang/scancode/MainActivity.java
class MainActivity (line 13) | public class MainActivity extends Activity {
method onCreate (line 14) | @Override
method clickListener (line 28) | @OnClick({R.id.create_code,R.id.scan_2code,R.id.scan_bar_code,R.id.sca...
FILE: app/src/main/java/com/liang/scancode/defineview/MyImageView.java
class MyImageView (line 15) | public class MyImageView extends ImageView{
method MyImageView (line 17) | public MyImageView(Context context, AttributeSet attrs) {
method MyImageView (line 21) | public MyImageView(Context context) {
method onDraw (line 26) | @Override
method dp2px (line 49) | public int dp2px(float dpVal)
method t (line 55) | public int t(float dpVal){
method onMeasure (line 59) | @Override
FILE: app/src/main/java/com/liang/scancode/utils/Constant.java
type Constant (line 6) | public interface Constant {
FILE: app/src/main/java/com/liang/scancode/zxing/ScanListener.java
type ScanListener (line 12) | public interface ScanListener {
method scanResult (line 18) | public void scanResult(Result rawResult, Bundle bundle);
method scanError (line 23) | public void scanError(Exception e);
FILE: app/src/main/java/com/liang/scancode/zxing/ScanManager.java
class ScanManager (line 38) | public class ScanManager implements SurfaceHolder.Callback{
method ScanManager (line 69) | public ScanManager(Activity activity,SurfaceView scanPreview,View scan...
method ScanManager (line 91) | public ScanManager(ScanListener listener){
method onResume (line 95) | public void onResume(){
method onPause (line 120) | public void onPause() {
method onDestroy (line 132) | public void onDestroy() {
method surfaceCreated (line 137) | @Override
method surfaceChanged (line 148) | @Override
method surfaceDestroyed (line 153) | @Override
method initCamera (line 157) | void initCamera(SurfaceHolder surfaceHolder) {
method switchLight (line 190) | public void switchLight(){
method getHandler (line 198) | public Handler getHandler() {
method getCameraManager (line 202) | public CameraManager getCameraManager() {
method getCropRect (line 205) | public Rect getCropRect() {
method handleDecode (line 213) | public void handleDecode(Result rawResult, Bundle bundle) {
method handleDecodeError (line 222) | public void handleDecodeError(Exception e){
method initCrop (line 228) | void initCrop() {
method getStatusBarHeight (line 259) | int getStatusBarHeight() {
method scanningImage (line 276) | public void scanningImage(final String photo_path2) {
method reScan (line 313) | public void reScan(){
method isScanning (line 318) | public boolean isScanning(){
FILE: app/src/main/java/com/liang/scancode/zxing/camera/AutoFocusManager.java
class AutoFocusManager (line 30) | public class AutoFocusManager implements Camera.AutoFocusCallback {
method AutoFocusManager (line 49) | public AutoFocusManager(Context context, Camera camera) {
method onAutoFocus (line 57) | @Override
method autoFocusAgainLater (line 63) | @SuppressLint("NewApi")
method start (line 80) | public synchronized void start() {
method cancelOutstandingTask (line 98) | synchronized void cancelOutstandingTask() {
method stop (line 107) | public synchronized void stop() {
class AutoFocusTask (line 122) | final class AutoFocusTask extends AsyncTask<Object, Object, Object> {
method doInBackground (line 123) | @Override
FILE: app/src/main/java/com/liang/scancode/zxing/camera/CameraConfigurationManager.java
class CameraConfigurationManager (line 43) | public final class CameraConfigurationManager {
method CameraConfigurationManager (line 57) | public CameraConfigurationManager(Context context) {
method initFromCameraParameters (line 61) | public void initFromCameraParameters(Camera camera) {
method getDisplaySize (line 86) | @SuppressWarnings("deprecation")
method setDesiredCameraParameters (line 99) | public void setDesiredCameraParameters(Camera camera, boolean safeMode) {
method getCameraResolution (line 128) | public Point getCameraResolution() {
method getScreenResolution (line 132) | public Point getScreenResolution() {
method findBestPreviewSizeValue (line 143) | Point findBestPreviewSizeValue(Camera.Parameters parameters, Point scr...
FILE: app/src/main/java/com/liang/scancode/zxing/camera/CameraManager.java
class CameraManager (line 39) | public class CameraManager {
method CameraManager (line 61) | public CameraManager(Context context) {
method openDriver (line 76) | public synchronized void openDriver(SurfaceHolder holder) throws IOExc...
method isOpen (line 124) | public synchronized boolean isOpen() {
method closeDriver (line 131) | public synchronized void closeDriver() {
method startPreview (line 144) | public synchronized void startPreview() {
method stopPreview (line 156) | public synchronized void stopPreview() {
method requestPreviewFrame (line 178) | public synchronized void requestPreviewFrame(Handler handler, int mess...
method setManualCameraId (line 194) | public synchronized void setManualCameraId(int cameraId) {
method getCameraResolution (line 203) | public Point getCameraResolution() {
method getPreviewSize (line 207) | public Size getPreviewSize() {
method openLight (line 217) | public void openLight() {
method offLight (line 227) | public void offLight() {
FILE: app/src/main/java/com/liang/scancode/zxing/camera/PreviewCallback.java
class PreviewCallback (line 25) | public class PreviewCallback implements Camera.PreviewCallback {
method PreviewCallback (line 33) | public PreviewCallback(CameraConfigurationManager configManager) {
method setHandler (line 37) | public void setHandler(Handler previewHandler, int previewMessage) {
method onPreviewFrame (line 42) | @Override
FILE: app/src/main/java/com/liang/scancode/zxing/camera/open/OpenCameraInterface.java
class OpenCameraInterface (line 22) | public class OpenCameraInterface {
method open (line 34) | public static Camera open(int cameraId) {
method open (line 82) | public static Camera open() {
FILE: app/src/main/java/com/liang/scancode/zxing/decode/DecodeFormatManager.java
class DecodeFormatManager (line 25) | public class DecodeFormatManager {
method getQrCodeFormats (line 44) | public static Collection<BarcodeFormat> getQrCodeFormats() {
method getBarCodeFormats (line 48) | public static Collection<BarcodeFormat> getBarCodeFormats() {
FILE: app/src/main/java/com/liang/scancode/zxing/decode/DecodeHandler.java
class DecodeHandler (line 40) | public class DecodeHandler extends Handler {
method DecodeHandler (line 46) | public DecodeHandler(ScanManager scanManager, Map<DecodeHintType, Obje...
method handleMessage (line 52) | @Override
method decode (line 80) | void decode(byte[] data, int width, int height) {
method bundleThumbnail (line 127) | static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bu...
method buildLuminanceSource (line 149) | public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int ...
FILE: app/src/main/java/com/liang/scancode/zxing/decode/DecodeThread.java
class DecodeThread (line 39) | public class DecodeThread extends Thread {
method DecodeThread (line 52) | public DecodeThread(ScanManager scanManager, int decodeMode) {
method getHandler (line 84) | public Handler getHandler() {
method run (line 93) | @Override
method getHints (line 101) | public static Map<DecodeHintType, Object> getHints() {
FILE: app/src/main/java/com/liang/scancode/zxing/decode/PhotoScanHandler.java
class PhotoScanHandler (line 11) | public class PhotoScanHandler extends Handler{
method PhotoScanHandler (line 15) | public PhotoScanHandler(ScanManager scanManager) {
method handleMessage (line 18) | @Override
FILE: app/src/main/java/com/liang/scancode/zxing/decode/RGBLuminanceSource.java
class RGBLuminanceSource (line 33) | public final class RGBLuminanceSource extends LuminanceSource {
method RGBLuminanceSource (line 36) | public RGBLuminanceSource(String path) throws FileNotFoundException {
method RGBLuminanceSource (line 40) | public RGBLuminanceSource(Bitmap bitmap) {
method getRow (line 69) | @Override
method getMatrix (line 86) | @Override
method loadBitmap (line 91) | static Bitmap loadBitmap(String path) throws FileNotFoundException {
FILE: app/src/main/java/com/liang/scancode/zxing/decode/Utils.java
class Utils (line 18) | public class Utils {
method getPath (line 19) | @SuppressLint("NewApi")
method getDataColumn (line 82) | public static String getDataColumn(Context context, Uri uri,
method isExternalStorageDocument (line 103) | public static boolean isExternalStorageDocument(Uri uri) {
method isDownloadsDocument (line 108) | public static boolean isDownloadsDocument(Uri uri) {
method isMediaDocument (line 113) | public static boolean isMediaDocument(Uri uri) {
method readPictureDegree (line 122) | public static int readPictureDegree(String path) {
method rotaingImageView (line 149) | public static Bitmap rotaingImageView(int angle , Bitmap bitmap) {
FILE: app/src/main/java/com/liang/scancode/zxing/encode/EncodingHandler.java
class EncodingHandler (line 20) | public final class EncodingHandler {
method create2Code (line 32) | public static Bitmap create2Code(String str, int widthAndHeight) throw...
method createBarCode (line 45) | public static Bitmap createBarCode(String str, Integer width, Integer ...
method getEncodeHintMap (line 53) | private static Hashtable<EncodeHintType, Object> getEncodeHintMap() {
method BitMatrixToBitmap (line 67) | private static Bitmap BitMatrixToBitmap(BitMatrix matrix) {
FILE: app/src/main/java/com/liang/scancode/zxing/utils/AppliationUtil.java
class AppliationUtil (line 6) | public class AppliationUtil {
FILE: app/src/main/java/com/liang/scancode/zxing/utils/BeepManager.java
class BeepManager (line 38) | public class BeepManager implements MediaPlayer.OnCompletionListener, Me...
method BeepManager (line 50) | public BeepManager(Activity activity) {
method updatePrefs (line 56) | synchronized void updatePrefs() {
method playBeepSoundAndVibrate (line 69) | public synchronized void playBeepSoundAndVibrate() {
method shouldBeep (line 79) | static boolean shouldBeep(SharedPreferences prefs, Context activity) {
method buildMediaPlayer (line 91) | MediaPlayer buildMediaPlayer(Context activity) {
method onCompletion (line 113) | @Override
method onError (line 119) | @Override
method close (line 134) | @Override
FILE: app/src/main/java/com/liang/scancode/zxing/utils/BitmapUtil.java
class BitmapUtil (line 10) | public class BitmapUtil {
method calculateInSampleSize (line 20) | public static int calculateInSampleSize(BitmapFactory.Options options,
method decodeBitmapFromPath (line 45) | public static Bitmap decodeBitmapFromPath(String photo_path, int reqWi...
FILE: app/src/main/java/com/liang/scancode/zxing/utils/CaptureActivityHandler.java
class CaptureActivityHandler (line 35) | public class CaptureActivityHandler extends Handler {
type State (line 42) | enum State {
method CaptureActivityHandler (line 46) | public CaptureActivityHandler(ScanManager scanManager, CameraManager c...
method handleMessage (line 58) | @Override
method quitSynchronously (line 86) | public void quitSynchronously() {
method restartPreviewAndDecode (line 104) | void restartPreviewAndDecode() {
method isScanning (line 114) | public boolean isScanning() {
FILE: app/src/main/java/com/liang/scancode/zxing/utils/InactivityTimer.java
class InactivityTimer (line 34) | public class InactivityTimer {
method InactivityTimer (line 45) | public InactivityTimer(Activity activity) {
method onActivity (line 52) | @SuppressLint("NewApi")
method onPause (line 63) | public synchronized void onPause() {
method onResume (line 73) | public synchronized void onResume() {
method cancel (line 83) | synchronized void cancel() {
method shutdown (line 91) | public void shutdown() {
class PowerStatusReceiver (line 95) | class PowerStatusReceiver extends BroadcastReceiver {
method onReceive (line 96) | @Override
class InactivityAsyncTask (line 110) | class InactivityAsyncTask extends AsyncTask<Object, Object, Object> {
method doInBackground (line 111) | @Override
Condensed preview — 74 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (148K chars).
[
{
"path": ".gitignore",
"chars": 463,
"preview": ".gradle\n/local.properties\n/.idea/workspace.xml\n/.idea/libraries\n.DS_Store\n/build\n/captures\n### Android template\n# Built "
},
{
"path": ".idea/.name",
"chars": 8,
"preview": "ScanCode"
},
{
"path": ".idea/compiler.xml",
"chars": 686,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"CompilerConfiguration\">\n <resourceExt"
},
{
"path": ".idea/copyright/profiles_settings.xml",
"chars": 74,
"preview": "<component name=\"CopyrightManager\">\n <settings default=\"\" />\n</component>"
},
{
"path": ".idea/encodings.xml",
"chars": 159,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"Encoding\">\n <file url=\"PROJECT\" chars"
},
{
"path": ".idea/gradle.xml",
"chars": 687,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"GradleSettings\">\n <option name=\"linke"
},
{
"path": ".idea/misc.xml",
"chars": 2226,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"EntryPointsManager\">\n <entry_points v"
},
{
"path": ".idea/modules.xml",
"chars": 353,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"ProjectModuleManager\">\n <modules>\n "
},
{
"path": ".idea/runConfigurations.xml",
"chars": 564,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"RunConfigurationProducerService\">\n <o"
},
{
"path": ".idea/vcs.xml",
"chars": 180,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"VcsDirectoryMappings\">\n <mapping dire"
},
{
"path": "README.md",
"chars": 755,
"preview": "# ScanCode\n使用zxing封装的android扫描全功能系列,包括二维码扫描,条形码扫描,二维码生成,条形码生成,从图片中扫描二维码或者条形码,闪光灯控制。<br/>\n优点:<br/>\n 1.该有的功能一个都不少!<br/>"
},
{
"path": "ScanCode.iml",
"chars": 939,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<module external.linked.project.id=\"ScanCode\" external.linked.project.path=\"$MODU"
},
{
"path": "app/.gitignore",
"chars": 379,
"preview": "### Android template\n# Built application files\n*.apk\n*.ap_\n\n# Files for the Dalvik VM\n*.dex\n\n# Java class files\n*.class\n"
},
{
"path": "app/app.iml",
"chars": 7245,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<module external.linked.project.id=\":app\" external.linked.project.path=\"$MODULE_D"
},
{
"path": "app/build.gradle",
"chars": 530,
"preview": "apply plugin: 'com.android.application'\n\nandroid {\n compileSdkVersion 22\n buildToolsVersion \"22.0.1\"\n\n defaultC"
},
{
"path": "app/proguard-rules.pro",
"chars": 661,
"preview": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in /h"
},
{
"path": "app/src/main/AndroidManifest.xml",
"chars": 2055,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n package="
},
{
"path": "app/src/main/java/com/liang/scancode/CommonScanActivity.java",
"chars": 7879,
"preview": "/*\n * Copyright (C) 2008 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may "
},
{
"path": "app/src/main/java/com/liang/scancode/CreateCodeActivity.java",
"chars": 4247,
"preview": "package com.liang.scancode;\n\nimport android.app.Activity;\nimport android.graphics.Bitmap;\nimport android.graphics.Bitmap"
},
{
"path": "app/src/main/java/com/liang/scancode/MainActivity.java",
"chars": 1863,
"preview": "package com.liang.scancode;\n\nimport android.app.Activity;\nimport android.content.Intent;\nimport android.os.Bundle;\nimpor"
},
{
"path": "app/src/main/java/com/liang/scancode/defineview/MyImageView.java",
"chars": 1882,
"preview": "package com.liang.scancode.defineview;\n\nimport android.content.Context;\nimport android.graphics.Canvas;\nimport android.g"
},
{
"path": "app/src/main/java/com/liang/scancode/utils/Constant.java",
"chars": 979,
"preview": "package com.liang.scancode.utils;\n\n/**\n * Created by 刘红亮 on 2015/9/24 14:08.\n */\npublic interface Constant {\n /**\n "
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/ScanListener.java",
"chars": 402,
"preview": "package com.liang.scancode.zxing;\n\nimport android.os.Bundle;\n\nimport com.google.zxing.Result;\n\n/**\n * 二维码结果监听返回\n * @auth"
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/ScanManager.java",
"chars": 9353,
"preview": "package com.liang.scancode.zxing;\n\nimport android.app.Activity;\nimport android.graphics.Bitmap;\nimport android.graphics."
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/camera/AutoFocusManager.java",
"chars": 3779,
"preview": "/*\n * Copyright (C) 2012 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may "
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/camera/CameraConfigurationManager.java",
"chars": 7448,
"preview": "/*\n * Copyright (C) 2008 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may "
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/camera/CameraManager.java",
"chars": 6455,
"preview": "/*\n * Copyright (C) 2008 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may "
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/camera/PreviewCallback.java",
"chars": 1792,
"preview": "/*\n * Copyright (C) 2010 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may "
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/camera/open/OpenCameraInterface.java",
"chars": 2261,
"preview": "/*\n * Copyright (C) 2012 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may "
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/decode/DecodeFormatManager.java",
"chars": 1684,
"preview": "/*\n * Copyright (C) 2010 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may "
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/decode/DecodeHandler.java",
"chars": 4866,
"preview": "/*\n * Copyright (C) 2010 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may "
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/decode/DecodeThread.java",
"chars": 2775,
"preview": "/*\n * Copyright (C) 2008 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may "
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/decode/PhotoScanHandler.java",
"chars": 789,
"preview": "package com.liang.scancode.zxing.decode;\n\nimport android.os.Bundle;\nimport android.os.Handler;\nimport android.os.Message"
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/decode/RGBLuminanceSource.java",
"chars": 3020,
"preview": "package com.liang.scancode.zxing.decode;\n\n/*\n * Copyright 2009 ZXing authors\n *\n * Licensed under the Apache License, Ve"
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/decode/Utils.java",
"chars": 5620,
"preview": "package com.liang.scancode.zxing.decode;\n\nimport android.annotation.SuppressLint;\nimport android.content.ContentUris;\nim"
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/encode/EncodingHandler.java",
"chars": 2943,
"preview": "package com.liang.scancode.zxing.encode;\n\nimport android.graphics.Bitmap;\nimport android.util.Log;\n\nimport com.google.zx"
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/utils/AppliationUtil.java",
"chars": 445,
"preview": "package com.liang.scancode.zxing.utils;\n\n/**\n * Created by 刘红亮 on 2015/7/23 22:35.\n */\npublic class AppliationUtil {\n "
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/utils/BeepManager.java",
"chars": 4042,
"preview": "/*\n * Copyright (C) 2010 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may "
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/utils/BitmapUtil.java",
"chars": 2019,
"preview": "package com.liang.scancode.zxing.utils;\n\nimport android.graphics.Bitmap;\nimport android.graphics.BitmapFactory;\nimport a"
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/utils/CaptureActivityHandler.java",
"chars": 3375,
"preview": "/*\n * Copyright (C) 2008 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may "
},
{
"path": "app/src/main/java/com/liang/scancode/zxing/utils/InactivityTimer.java",
"chars": 3316,
"preview": "/*\n * Copyright (C) 2010 ZXing authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may "
},
{
"path": "app/src/main/res/anim/popupwin_nearperson_exit.xml",
"chars": 320,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<set xmlns:android=\"http://schemas.android.com/apk/res/android\"\n\tandroid:interpol"
},
{
"path": "app/src/main/res/anim/popupwin_nearperson_show.xml",
"chars": 320,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<set xmlns:android=\"http://schemas.android.com/apk/res/android\"\n\tandroid:interpol"
},
{
"path": "app/src/main/res/anim/shouquan_dialog_enter.xml",
"chars": 204,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<set xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <!-- from从始点"
},
{
"path": "app/src/main/res/anim/shouquan_dialog_exit.xml",
"chars": 199,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<set xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <!-- to从终点技术"
},
{
"path": "app/src/main/res/drawable/base_bgpic.xml",
"chars": 737,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n<shape\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n androi"
},
{
"path": "app/src/main/res/drawable/rescan_shape_button.xml",
"chars": 322,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<shape xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:sha"
},
{
"path": "app/src/main/res/drawable/shouquan_bg_loading_dialog_shape.xml",
"chars": 203,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<shape xmlns:android=\"http://schemas.android.com/apk/res/android\" >\n <corners "
},
{
"path": "app/src/main/res/drawable/shouquan_loading_dialog_progressbar.xml",
"chars": 227,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<animated-rotate xmlns:android=\"http://schemas.android.com/apk/res/android\"\n a"
},
{
"path": "app/src/main/res/drawable/shouquan_qrcode_g_gallery.xml",
"chars": 283,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<selector xmlns:android=\"http://schemas.android.com/apk/res/android\">\n\n <item "
},
{
"path": "app/src/main/res/drawable/shouquan_qrcode_ic_back.xml",
"chars": 282,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<selector xmlns:android=\"http://schemas.android.com/apk/res/android\">\n\n <item "
},
{
"path": "app/src/main/res/drawable/shouquan_qrcode_s_flashgun.xml",
"chars": 282,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<selector xmlns:android=\"http://schemas.android.com/apk/res/android\">\n\n <item "
},
{
"path": "app/src/main/res/layout/activity_create_code.xml",
"chars": 1884,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n andr"
},
{
"path": "app/src/main/res/layout/activity_main.xml",
"chars": 1665,
"preview": "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:tools=\"http://schemas.android.com/too"
},
{
"path": "app/src/main/res/layout/activity_scan_code.xml",
"chars": 6856,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n an"
},
{
"path": "app/src/main/res/layout/activity_scan_result.xml",
"chars": 1740,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n andr"
},
{
"path": "app/src/main/res/menu/menu_jump_to.xml",
"chars": 339,
"preview": "<menu xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:tools=\"http://schemas.android.com/tools\"\n "
},
{
"path": "app/src/main/res/menu/menu_sao_mao.xml",
"chars": 339,
"preview": "<menu xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:tools=\"http://schemas.android.com/tools\"\n "
},
{
"path": "app/src/main/res/values/Qrcode_ids.xml",
"chars": 936,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!--\n Copyright (C) 2008 ZXing authors\n\n Licensed under the Apache License, Versi"
},
{
"path": "app/src/main/res/values/colors.xml",
"chars": 112,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <color name=\"scan_bg\">#7f000000</color>\n \n</resources>"
},
{
"path": "app/src/main/res/values/dimens.xml",
"chars": 211,
"preview": "<resources>\n <!-- Default screen margins, per the Android Design guidelines. -->\n <dimen name=\"activity_horizontal"
},
{
"path": "app/src/main/res/values/strings.xml",
"chars": 766,
"preview": "<resources>\n <string name=\"app_name\">Scan2Code</string>\n\n <string name=\"hello_world\">Hello world!</string>\n <st"
},
{
"path": "app/src/main/res/values/styles.xml",
"chars": 1480,
"preview": "<resources>\n\n <!-- Base application theme. -->\n <style name=\"AppTheme\">\n <!-- Customize your theme here. --"
},
{
"path": "app/src/main/res/values-w820dp/dimens.xml",
"chars": 358,
"preview": "<resources>\n <!-- Example customization of dimensions originally defined in res/values/dimens.xml\n (such as s"
},
{
"path": "build.gradle",
"chars": 436,
"preview": "// Top-level build file where you can add configuration options common to all sub-projects/modules.\n\nbuildscript {\n r"
},
{
"path": "gradle/wrapper/gradle-wrapper.properties",
"chars": 232,
"preview": "#Wed Apr 10 15:27:10 PDT 2013\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_"
},
{
"path": "gradle.properties",
"chars": 817,
"preview": "## Project-wide Gradle settings.\n#\n# For more details on how to configure your build environment visit\n# http://www.grad"
},
{
"path": "gradlew",
"chars": 5080,
"preview": "#!/usr/bin/env bash\n\n##############################################################################\n##\n## Gradle start "
},
{
"path": "gradlew.bat",
"chars": 2314,
"preview": "@if \"%DEBUG%\" == \"\" @echo off\n@rem ##########################################################################\n@rem\n@rem "
},
{
"path": "settings.gradle",
"chars": 15,
"preview": "include ':app'\n"
}
]
// ... and 4 more files (download for full content)
About this extraction
This page contains the full source code of the liang530/ScanCode GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 74 files (127.1 KB), approximately 34.5k tokens, and a symbol index with 157 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.