├── .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-hdpi │ ├── arrow.png │ ├── flashlight.png │ ├── ic_orderform_arrow_fanhui.png │ └── kai.png │ ├── drawable-xhdpi │ ├── arrow.png │ ├── flashlight.png │ ├── ic_my_returns_arrow.png │ ├── ic_orderform_arrow_fanhui.png │ ├── ic_seller_seeps.png │ ├── kai.png │ ├── scan2code_icon_back_nor.png │ ├── scan2code_icon_back_sel.png │ ├── scan2code_icon_light_nor.png │ ├── scan2code_icon_light_sel.png │ ├── scan2code_icon_xiangce.png │ ├── scan2code_icon_xiangce_sel.png │ ├── scanning_line.png │ ├── shouquan_icon_error.png │ ├── shouquan_icon_ok.png │ ├── shouquan_iloading_progress.png │ └── yundan_scanline.png │ ├── drawable-xxhdpi │ ├── arrow.png │ ├── flashlight.png │ ├── ic_orderform_arrow_fanhui.png │ ├── ic_seller_seeps.png │ └── kai.png │ ├── drawable │ ├── base_bgpic.xml │ ├── head.jpg │ ├── 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 │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── raw │ └── beep.ogg │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── Qrcode_ids.xml │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images ├── createCode.png ├── main.png ├── scan2code.png ├── scanCode.png ├── scan_bar_code.png └── scan_photo.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | ### Android template 9 | # Built application files 10 | *.apk 11 | *.ap_ 12 | 13 | # Files for the Dalvik VM 14 | *.dex 15 | 16 | # Java class files 17 | *.class 18 | 19 | # Generated files 20 | bin/ 21 | gen/ 22 | 23 | # Gradle files 24 | .gradle/ 25 | build/ 26 | 27 | # Local configuration file (sdk path, etc) 28 | local.properties 29 | 30 | # Proguard folder generated by Eclipse 31 | proguard/ 32 | 33 | # Log Files 34 | *.log 35 | 36 | # Android Studio Navigation editor temp files 37 | .navigation/ 38 | 39 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | ScanCode -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ScanCode 2 | 使用zxing封装的android扫描全功能系列,包括二维码扫描,条形码扫描,二维码生成,条形码生成,从图片中扫描二维码或者条形码,闪光灯控制。
3 | 优点:
4 | 1.该有的功能一个都不少!
5 | 2.扫描界面布局xml完成,可自行订制!
6 | 3.不乱码,不变形!
7 | 4.扫描后可得到扫描的截图!
8 | 5.支持连续扫描!
9 | 6.在一个项目中可多处使用,根据CommonScanActivity在多写一个自己的扫描界面就行了!
10 | #项目截图 11 | ![](https://github.com/liang530/ScanCode/raw/master/images/main.png)
12 | 13 | ![](https://github.com/liang530/ScanCode/raw/master/images/createCode.png)
14 | ![](https://github.com/liang530/ScanCode/raw/master/images/scanCode.png)
15 | ![](https://github.com/liang530/ScanCode/raw/master/images/scan2code.png)
16 | ![](https://github.com/liang530/ScanCode/raw/master/images/scan_bar_code.png)
17 | ![](https://github.com/liang530/ScanCode/raw/master/images/scan_photo.png)
18 | -------------------------------------------------------------------------------- /ScanCode.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | ### Android template 2 | # Built application files 3 | *.apk 4 | *.ap_ 5 | 6 | # Files for the Dalvik VM 7 | *.dex 8 | 9 | # Java class files 10 | *.class 11 | 12 | # Generated files 13 | bin/ 14 | gen/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | /build 33 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.liang.scancode" 9 | minSdkVersion 15 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | } 25 | -------------------------------------------------------------------------------- /app/libs/butterknife-7.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/libs/butterknife-7.0.1.jar -------------------------------------------------------------------------------- /app/libs/zxing.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/libs/zxing.jar -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/hongliang/android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class goodsid to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 26 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 41 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/CommonScanActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.liang.scancode; 17 | 18 | import android.app.Activity; 19 | import android.content.Intent; 20 | import android.database.Cursor; 21 | import android.graphics.Bitmap; 22 | import android.graphics.BitmapFactory; 23 | import android.os.Bundle; 24 | import android.provider.MediaStore; 25 | import android.view.SurfaceView; 26 | import android.view.View; 27 | import android.view.Window; 28 | import android.view.WindowManager; 29 | import android.widget.Button; 30 | import android.widget.ImageView; 31 | import android.widget.TextView; 32 | import android.widget.Toast; 33 | 34 | import com.google.zxing.Result; 35 | 36 | import butterknife.ButterKnife; 37 | import butterknife.Bind; 38 | import com.liang.scancode.utils.Constant; 39 | import com.liang.scancode.zxing.ScanListener; 40 | import com.liang.scancode.zxing.ScanManager; 41 | import com.liang.scancode.zxing.decode.DecodeThread; 42 | import com.liang.scancode.zxing.decode.Utils; 43 | 44 | 45 | /** 46 | * 二维码扫描使用 47 | * 48 | * @author 刘红亮 2015年4月29日 下午5:49:45 49 | */ 50 | public final class CommonScanActivity extends Activity implements ScanListener, View.OnClickListener { 51 | static final String TAG = CommonScanActivity.class.getSimpleName(); 52 | SurfaceView scanPreview = null; 53 | View scanContainer; 54 | View scanCropView; 55 | ImageView scanLine; 56 | ScanManager scanManager; 57 | TextView iv_light; 58 | TextView qrcode_g_gallery; 59 | TextView qrcode_ic_back; 60 | final int PHOTOREQUESTCODE = 1111; 61 | 62 | @Bind(R.id.service_register_rescan) 63 | Button rescan; 64 | @Bind(R.id.scan_image) 65 | ImageView scan_image; 66 | @Bind(R.id.authorize_return) 67 | ImageView authorize_return; 68 | private int scanMode;//扫描模型(条形,二维码,全部) 69 | 70 | @Bind(R.id.common_title_TV_center) 71 | TextView title; 72 | @Bind(R.id.scan_hint) 73 | TextView scan_hint; 74 | @Bind(R.id.tv_scan_result) 75 | TextView tv_scan_result; 76 | 77 | 78 | 79 | @Override 80 | public void onCreate(Bundle icicle) { 81 | super.onCreate(icicle); 82 | 83 | Window window = getWindow(); 84 | window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 85 | setContentView(R.layout.activity_scan_code); 86 | ButterKnife.bind(this); 87 | scanMode=getIntent().getIntExtra(Constant.REQUEST_SCAN_MODE,Constant.REQUEST_SCAN_MODE_ALL_MODE); 88 | initView(); 89 | } 90 | 91 | void initView() { 92 | switch (scanMode){ 93 | case DecodeThread.BARCODE_MODE: 94 | title.setText(R.string.scan_barcode_title); 95 | scan_hint.setText(R.string.scan_barcode_hint); 96 | break; 97 | case DecodeThread.QRCODE_MODE: 98 | title.setText(R.string.scan_qrcode_title); 99 | scan_hint.setText(R.string.scan_qrcode_hint); 100 | break; 101 | case DecodeThread.ALL_MODE: 102 | title.setText(R.string.scan_allcode_title); 103 | scan_hint.setText(R.string.scan_allcode_hint); 104 | break; 105 | } 106 | scanPreview = (SurfaceView) findViewById(R.id.capture_preview); 107 | scanContainer = findViewById(R.id.capture_container); 108 | scanCropView = findViewById(R.id.capture_crop_view); 109 | scanLine = (ImageView) findViewById(R.id.capture_scan_line); 110 | qrcode_g_gallery = (TextView) findViewById(R.id.qrcode_g_gallery); 111 | qrcode_g_gallery.setOnClickListener(this); 112 | qrcode_ic_back = (TextView) findViewById(R.id.qrcode_ic_back); 113 | qrcode_ic_back.setOnClickListener(this); 114 | iv_light = (TextView) findViewById(R.id.iv_light); 115 | iv_light.setOnClickListener(this); 116 | rescan.setOnClickListener(this); 117 | authorize_return.setOnClickListener(this); 118 | //构造出扫描管理器 119 | scanManager = new ScanManager(this, scanPreview, scanContainer, scanCropView, scanLine, scanMode,this); 120 | } 121 | 122 | @Override 123 | public void onResume() { 124 | super.onResume(); 125 | scanManager.onResume(); 126 | rescan.setVisibility(View.INVISIBLE); 127 | scan_image.setVisibility(View.GONE); 128 | } 129 | 130 | @Override 131 | public void onPause() { 132 | super.onPause(); 133 | scanManager.onPause(); 134 | } 135 | /** 136 | * 137 | */ 138 | public void scanResult(Result rawResult, Bundle bundle) { 139 | //扫描成功后,扫描器不会再连续扫描,如需连续扫描,调用reScan()方法。 140 | //scanManager.reScan(); 141 | // Toast.makeText(that, "result="+rawResult.getText(), Toast.LENGTH_LONG).show(); 142 | 143 | if (!scanManager.isScanning()) { //如果当前不是在扫描状态 144 | //设置再次扫描按钮出现 145 | rescan.setVisibility(View.VISIBLE); 146 | scan_image.setVisibility(View.VISIBLE); 147 | Bitmap barcode = null; 148 | byte[] compressedBitmap = bundle.getByteArray(DecodeThread.BARCODE_BITMAP); 149 | if (compressedBitmap != null) { 150 | barcode = BitmapFactory.decodeByteArray(compressedBitmap, 0, compressedBitmap.length, null); 151 | barcode = barcode.copy(Bitmap.Config.ARGB_8888, true); 152 | } 153 | scan_image.setImageBitmap(barcode); 154 | } 155 | rescan.setVisibility(View.VISIBLE); 156 | scan_image.setVisibility(View.VISIBLE); 157 | tv_scan_result.setVisibility(View.VISIBLE); 158 | tv_scan_result.setText("结果:"+rawResult.getText()); 159 | } 160 | 161 | void startScan() { 162 | if (rescan.getVisibility() == View.VISIBLE) { 163 | rescan.setVisibility(View.INVISIBLE); 164 | scan_image.setVisibility(View.GONE); 165 | scanManager.reScan(); 166 | } 167 | } 168 | 169 | @Override 170 | public void scanError(Exception e) { 171 | Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); 172 | //相机扫描出错时 173 | if(e.getMessage()!=null&&e.getMessage().startsWith("相机")){ 174 | scanPreview.setVisibility(View.INVISIBLE); 175 | } 176 | } 177 | 178 | public void showPictures(int requestCode) { 179 | Intent intent = new Intent(Intent.ACTION_PICK); 180 | intent.setType("image/*"); 181 | startActivityForResult(intent, requestCode); 182 | } 183 | 184 | @Override 185 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 186 | super.onActivityResult(requestCode, resultCode, data); 187 | String photo_path; 188 | if (resultCode == RESULT_OK) { 189 | switch (requestCode) { 190 | case PHOTOREQUESTCODE: 191 | String[] proj = {MediaStore.Images.Media.DATA}; 192 | Cursor cursor = this.getContentResolver().query(data.getData(), proj, null, null, null); 193 | if (cursor.moveToFirst()) { 194 | int colum_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 195 | photo_path = cursor.getString(colum_index); 196 | if (photo_path == null) { 197 | photo_path = Utils.getPath(getApplicationContext(), data.getData()); 198 | } 199 | scanManager.scanningImage(photo_path); 200 | } 201 | } 202 | } 203 | } 204 | 205 | @Override 206 | public void onClick(View v) { 207 | switch (v.getId()) { 208 | case R.id.qrcode_g_gallery: 209 | showPictures(PHOTOREQUESTCODE); 210 | break; 211 | case R.id.iv_light: 212 | scanManager.switchLight(); 213 | break; 214 | case R.id.qrcode_ic_back: 215 | finish(); 216 | break; 217 | case R.id.service_register_rescan://再次开启扫描 218 | startScan(); 219 | break; 220 | case R.id.authorize_return: 221 | finish(); 222 | break; 223 | default: 224 | break; 225 | } 226 | } 227 | 228 | } -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/CreateCodeActivity.java: -------------------------------------------------------------------------------- 1 | package com.liang.scancode; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Canvas; 7 | import android.graphics.Matrix; 8 | import android.graphics.Rect; 9 | import android.os.Bundle; 10 | import android.text.TextUtils; 11 | import android.view.View; 12 | import android.widget.Button; 13 | import android.widget.EditText; 14 | import android.widget.ImageView; 15 | import android.widget.Toast; 16 | 17 | import com.google.zxing.WriterException; 18 | 19 | import java.io.UnsupportedEncodingException; 20 | 21 | import butterknife.ButterKnife; 22 | import butterknife.Bind; 23 | import butterknife.OnClick; 24 | import com.liang.scancode.zxing.encode.EncodingHandler; 25 | 26 | /** 27 | * Created by 刘红亮 on 2015/9/24 14:37. 28 | */ 29 | public class CreateCodeActivity extends Activity { 30 | @Bind(R.id.et_code_key) 31 | EditText etCodeKey; 32 | @Bind(R.id.btn_create_code) 33 | Button btnCreateCode; 34 | @Bind(R.id.iv_2_code) 35 | ImageView iv2Code; 36 | @Bind(R.id.iv_bar_code) 37 | ImageView ivBarCode; 38 | 39 | @Override 40 | public void onCreate(Bundle savedInstanceState) { 41 | super.onCreate(savedInstanceState); 42 | setContentView(R.layout.activity_create_code); 43 | ButterKnife.bind(this); 44 | } 45 | @OnClick({R.id.btn_create_code,R.id.btn_create_code_and_img}) 46 | public void clickListener(View view){ 47 | String key=etCodeKey.getText().toString(); 48 | switch (view.getId()){ 49 | case R.id.btn_create_code: //生成码 50 | if(TextUtils.isEmpty(key)){ 51 | Toast.makeText(this,"请输入内容",Toast.LENGTH_SHORT).show(); 52 | }else{ 53 | create2Code(key); 54 | createBarCode(key); 55 | } 56 | break; 57 | case R.id.btn_create_code_and_img: //生成码 58 | Bitmap bitmap = create2Code(key); 59 | Bitmap headBitmap = getHeadBitmap(60); 60 | if(bitmap!=null&&headBitmap!=null){ 61 | createQRCodeBitmapWithPortrait(bitmap,headBitmap); 62 | } 63 | break; 64 | } 65 | } 66 | private Bitmap createBarCode(String key) { 67 | Bitmap qrCode = null; 68 | try { 69 | qrCode = EncodingHandler.createBarCode(key, 600, 300); 70 | ivBarCode.setImageBitmap(qrCode); 71 | } catch (Exception e) { 72 | Toast.makeText(this,"输入的内容条形码不支持!",Toast.LENGTH_SHORT).show(); 73 | e.printStackTrace(); 74 | } 75 | return qrCode; 76 | } 77 | 78 | /** 79 | * 生成二维码 80 | * @param key 81 | */ 82 | private Bitmap create2Code(String key) { 83 | Bitmap qrCode=null; 84 | try { 85 | qrCode= EncodingHandler.create2Code(key, 400); 86 | iv2Code.setImageBitmap(qrCode); 87 | } catch (WriterException e) { 88 | e.printStackTrace(); 89 | } catch (UnsupportedEncodingException e) { 90 | e.printStackTrace(); 91 | } 92 | return qrCode; 93 | } 94 | /** 95 | * 初始化头像图片 96 | */ 97 | private Bitmap getHeadBitmap(int size) { 98 | try { 99 | // 这里采用从asset中加载图片abc.jpg 100 | Bitmap portrait = BitmapFactory.decodeResource(getResources(),R.drawable.head); 101 | // 对原有图片压缩显示大小 102 | Matrix mMatrix = new Matrix(); 103 | float width = portrait.getWidth(); 104 | float height = portrait.getHeight(); 105 | mMatrix.setScale(size / width, size / height); 106 | return Bitmap.createBitmap(portrait, 0, 0, (int) width, 107 | (int) height, mMatrix, true); 108 | } catch (Exception e) { 109 | e.printStackTrace(); 110 | } 111 | return null; 112 | } 113 | /** 114 | * 在二维码上绘制头像 115 | */ 116 | private void createQRCodeBitmapWithPortrait(Bitmap qr, Bitmap portrait) { 117 | // 头像图片的大小 118 | int portrait_W = portrait.getWidth(); 119 | int portrait_H = portrait.getHeight(); 120 | 121 | // 设置头像要显示的位置,即居中显示 122 | int left = (qr.getWidth() - portrait_W) / 2; 123 | int top = (qr.getHeight() - portrait_H) / 2; 124 | int right = left + portrait_W; 125 | int bottom = top + portrait_H; 126 | Rect rect1 = new Rect(left, top, right, bottom); 127 | 128 | // 取得qr二维码图片上的画笔,即要在二维码图片上绘制我们的头像 129 | Canvas canvas = new Canvas(qr); 130 | 131 | // 设置我们要绘制的范围大小,也就是头像的大小范围 132 | Rect rect2 = new Rect(0, 0, portrait_W, portrait_H); 133 | // 开始绘制 134 | canvas.drawBitmap(portrait, rect2, rect1, null); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.liang.scancode; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | import butterknife.ButterKnife; 9 | import butterknife.OnClick; 10 | import com.liang.scancode.utils.Constant; 11 | 12 | 13 | public class MainActivity extends Activity { 14 | @Override 15 | public void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | ButterKnife.bind(this); 19 | int mode = getIntent().getIntExtra(Constant.REQUEST_SCAN_MODE, Constant.REQUEST_SCAN_MODE_ALL_MODE); 20 | 21 | 22 | } 23 | 24 | /** 25 | * 按钮监听事件,这里我使用Butterknife,不喜欢的也可以直接写监听 26 | * @param view 27 | */ 28 | @OnClick({R.id.create_code,R.id.scan_2code,R.id.scan_bar_code,R.id.scan_code}) 29 | public void clickListener(View view){ 30 | Intent intent; 31 | switch (view.getId()){ 32 | case R.id.create_code: //生成码 33 | intent=new Intent(this,CreateCodeActivity.class); 34 | startActivity(intent); 35 | break; 36 | case R.id.scan_2code: //扫描二维码 37 | intent=new Intent(this,CommonScanActivity.class); 38 | intent.putExtra(Constant.REQUEST_SCAN_MODE,Constant.REQUEST_SCAN_MODE_QRCODE_MODE); 39 | startActivity(intent); 40 | break; 41 | case R.id.scan_bar_code://扫描条形码 42 | intent=new Intent(this,CommonScanActivity.class); 43 | intent.putExtra(Constant.REQUEST_SCAN_MODE,Constant.REQUEST_SCAN_MODE_BARCODE_MODE); 44 | startActivity(intent); 45 | break; 46 | case R.id.scan_code://扫描条形码或者二维码 47 | intent=new Intent(this,CommonScanActivity.class); 48 | intent.putExtra(Constant.REQUEST_SCAN_MODE,Constant.REQUEST_SCAN_MODE_ALL_MODE); 49 | startActivity(intent); 50 | break; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/defineview/MyImageView.java: -------------------------------------------------------------------------------- 1 | package com.liang.scancode.defineview; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Paint; 7 | import android.util.AttributeSet; 8 | import android.util.TypedValue; 9 | import android.widget.ImageView; 10 | 11 | /** 12 | * 作者:王敏 on 2015/8/21 17:31 13 | * 类说明:画出扫描框的四个脚的脚边框,也可以直接用一张图片代替 14 | */ 15 | public class MyImageView extends ImageView{ 16 | private Context context; 17 | public MyImageView(Context context, AttributeSet attrs) { 18 | super(context, attrs); 19 | this.context = context; 20 | } 21 | public MyImageView(Context context) { 22 | super(context); 23 | this.context = context; 24 | } 25 | 26 | @Override 27 | protected void onDraw(Canvas canvas) { 28 | super.onDraw(canvas); 29 | int width = getWidth(); 30 | int height = getHeight(); 31 | 32 | Paint paint = new Paint(); 33 | paint.setColor(Color.rgb(9,187,7)); 34 | paint.setAntiAlias(true); 35 | paint.setStrokeWidth(t(5)); 36 | 37 | canvas.drawLine(0, 0, 0, t(18), paint); 38 | canvas.drawLine(0, 0, t(18), 0, paint); 39 | 40 | canvas.drawLine(0, height - t(18), 0, height, paint); 41 | canvas.drawLine(0, height, t(18),height,paint); 42 | 43 | canvas.drawLine(width-t(18), 0, width, 0, paint); 44 | canvas.drawLine(width, 0, width,t(18),paint); 45 | 46 | canvas.drawLine(width, height-t(18), width, height, paint); 47 | canvas.drawLine(width-t(18), height, width,height,paint); 48 | } 49 | public int dp2px(float dpVal) 50 | { 51 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 52 | dpVal, context.getResources().getDisplayMetrics()); 53 | } 54 | 55 | public int t(float dpVal){ 56 | return dp2px(dpVal); 57 | } 58 | 59 | @Override 60 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 61 | super.onMeasure(widthMeasureSpec,heightMeasureSpec); 62 | // setMeasuredDimension(t(248),t(248)); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/utils/Constant.java: -------------------------------------------------------------------------------- 1 | package com.liang.scancode.utils; 2 | 3 | /** 4 | * Created by 刘红亮 on 2015/9/24 14:08. 5 | */ 6 | public interface Constant { 7 | /** 8 | * 二维码请求的type 9 | */ 10 | public static final String REQUEST_SCAN_TYPE="type"; 11 | /** 12 | * 普通类型,扫完即关闭 13 | */ 14 | public static final int REQUEST_SCAN_TYPE_COMMON=0; 15 | /** 16 | * 服务商登记类型,扫描 17 | */ 18 | public static final int REQUEST_SCAN_TYPE_REGIST=1; 19 | 20 | 21 | /** 22 | * 扫描类型 23 | * 条形码或者二维码:REQUEST_SCAN_MODE_ALL_MODE 24 | * 条形码: REQUEST_SCAN_MODE_BARCODE_MODE 25 | * 二维码:REQUEST_SCAN_MODE_QRCODE_MODE 26 | * 27 | */ 28 | public static final String REQUEST_SCAN_MODE="ScanMode"; 29 | /** 30 | * 条形码: REQUEST_SCAN_MODE_BARCODE_MODE 31 | */ 32 | public static final int REQUEST_SCAN_MODE_BARCODE_MODE = 0X100; 33 | /** 34 | * 二维码:REQUEST_SCAN_MODE_ALL_MODE 35 | */ 36 | public static final int REQUEST_SCAN_MODE_QRCODE_MODE = 0X200; 37 | /** 38 | * 条形码或者二维码:REQUEST_SCAN_MODE_ALL_MODE 39 | */ 40 | public static final int REQUEST_SCAN_MODE_ALL_MODE = 0X300; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/ScanListener.java: -------------------------------------------------------------------------------- 1 | package com.liang.scancode.zxing; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.google.zxing.Result; 6 | 7 | /** 8 | * 二维码结果监听返回 9 | * @author 刘红亮 2015年4月29日 下午8:08:13 10 | * 11 | */ 12 | public interface ScanListener { 13 | /** 14 | * 返回扫描结果 15 | * @param rawResult 结果对象 16 | * @param bundle 存放了截图,或者是空的 17 | */ 18 | public void scanResult(Result rawResult, Bundle bundle); 19 | /** 20 | * 扫描抛出的异常 21 | * @param e 22 | */ 23 | public void scanError(Exception e); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/ScanManager.java: -------------------------------------------------------------------------------- 1 | package com.liang.scancode.zxing; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Rect; 6 | import android.os.Bundle; 7 | import android.os.Handler; 8 | import android.os.Message; 9 | import android.text.TextUtils; 10 | import android.util.Log; 11 | import android.view.SurfaceHolder; 12 | import android.view.SurfaceView; 13 | import android.view.View; 14 | import android.view.animation.Animation; 15 | import android.view.animation.TranslateAnimation; 16 | import android.widget.ImageView; 17 | 18 | import com.google.zxing.BinaryBitmap; 19 | import com.google.zxing.DecodeHintType; 20 | import com.google.zxing.MultiFormatReader; 21 | import com.google.zxing.Result; 22 | import com.google.zxing.common.HybridBinarizer; 23 | import com.google.zxing.qrcode.QRCodeReader; 24 | import com.liang.scancode.R; 25 | import com.liang.scancode.zxing.camera.CameraManager; 26 | import com.liang.scancode.zxing.decode.DecodeThread; 27 | import com.liang.scancode.zxing.decode.PhotoScanHandler; 28 | import com.liang.scancode.zxing.decode.RGBLuminanceSource; 29 | import com.liang.scancode.zxing.utils.BeepManager; 30 | import com.liang.scancode.zxing.utils.BitmapUtil; 31 | import com.liang.scancode.zxing.utils.CaptureActivityHandler; 32 | import com.liang.scancode.zxing.utils.InactivityTimer; 33 | 34 | import java.io.IOException; 35 | import java.lang.reflect.Field; 36 | import java.util.Map; 37 | 38 | public class ScanManager implements SurfaceHolder.Callback{ 39 | boolean isHasSurface = false; 40 | CameraManager cameraManager; 41 | //用于拍摄扫描的handler 42 | CaptureActivityHandler handler; 43 | //用于照片扫描的handler,不可共用,图片扫描是不需要摄像机的 44 | PhotoScanHandler photoScanHandler; 45 | Rect mCropRect = null; 46 | InactivityTimer inactivityTimer; 47 | public BeepManager beepManager; 48 | SurfaceView scanPreview = null; 49 | View scanContainer; 50 | View scanCropView; 51 | ImageView scanLine; 52 | final String TAG= ScanManager.class.getSimpleName(); 53 | Activity activity; 54 | ScanListener listener; 55 | boolean isOpenLight=false; 56 | 57 | private int scanMode;//扫描模型(条形,二维码,全部) 58 | /** 59 | * 用于启动照相机扫描二维码,在activity的onCreate里面构造出来 60 | * 在activity的生命周期中调用此类相对应的生命周期方法 61 | * @param activity 扫描的activity 62 | * @param scanPreview 预览的SurfaceView 63 | * @param scanContainer 扫描的布局,全屏布局 64 | * @param scanCropView 扫描的矩形区域 65 | * @param scanLine 扫描线 66 | * 67 | * 68 | */ 69 | public ScanManager(Activity activity,SurfaceView scanPreview,View scanContainer, 70 | View scanCropView,ImageView scanLine,int scanMode,ScanListener listener) { 71 | this.activity=activity; 72 | this.scanPreview=scanPreview; 73 | this.scanContainer=scanContainer; 74 | this.scanCropView=scanCropView; 75 | this.scanLine=scanLine; 76 | this.listener=listener; 77 | this.scanMode=scanMode; 78 | //启动动画 79 | 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, 80 | 0.9f); 81 | animation.setDuration(4500); 82 | animation.setRepeatCount(-1); 83 | animation.setRepeatMode(Animation.RESTART); 84 | scanLine.startAnimation(animation); 85 | 86 | } 87 | /** 88 | * 用于图片扫描的构造函数 89 | * @param listener 结果的监听回调 90 | */ 91 | public ScanManager(ScanListener listener){ 92 | this.listener=listener; 93 | } 94 | 95 | public void onResume(){ 96 | // CameraManager must be initialized here, not in onCreate(). This is 97 | // necessary because we don't 98 | // want to open the camera driver and measure the screen size if we're 99 | // going to show the help on 100 | // first launch. That led to bugs where the scanning rectangle was the 101 | // wrong size and partially 102 | // off screen. 103 | inactivityTimer = new InactivityTimer(activity); 104 | beepManager = new BeepManager(activity); 105 | cameraManager = new CameraManager(activity.getApplicationContext()); 106 | 107 | handler = null; 108 | if (isHasSurface) { 109 | // The activity was paused but not stopped, so the surface still 110 | // exists. Therefore 111 | // surfaceCreated() won't be called, so init the camera here. 112 | initCamera(scanPreview.getHolder()); 113 | } else { 114 | // Install the callback and wait for surfaceCreated() to init the 115 | // camera. 116 | scanPreview.getHolder().addCallback(this); 117 | } 118 | inactivityTimer.onResume(); 119 | } 120 | public void onPause() { 121 | if (handler != null) { 122 | handler.quitSynchronously(); 123 | handler = null; 124 | } 125 | inactivityTimer.onPause(); 126 | beepManager.close(); 127 | cameraManager.closeDriver(); 128 | if (!isHasSurface) { 129 | scanPreview.getHolder().removeCallback(this); 130 | } 131 | } 132 | public void onDestroy() { 133 | inactivityTimer.shutdown(); 134 | } 135 | 136 | 137 | @Override 138 | public void surfaceCreated(SurfaceHolder holder) { 139 | if (holder == null) { 140 | Log.e(TAG, "*** WARNING *** surfaceCreated() gave us a null surface!"); 141 | } 142 | if (!isHasSurface) { 143 | isHasSurface = true; 144 | initCamera(holder); 145 | } 146 | } 147 | 148 | @Override 149 | public void surfaceChanged(SurfaceHolder holder, int format, int width, 150 | int height) { 151 | } 152 | 153 | @Override 154 | public void surfaceDestroyed(SurfaceHolder holder) { 155 | isHasSurface = false; 156 | } 157 | void initCamera(SurfaceHolder surfaceHolder) { 158 | if (surfaceHolder == null) { 159 | throw new IllegalStateException("No SurfaceHolder provided"); 160 | } 161 | if (cameraManager.isOpen()) { 162 | Log.w(TAG, "initCamera() while already open -- late SurfaceView callback?"); 163 | return; 164 | } 165 | try { 166 | cameraManager.openDriver(surfaceHolder); 167 | // Creating the handler starts the preview, which can also throw a 168 | // RuntimeException. 169 | if (handler == null) { 170 | handler = new CaptureActivityHandler(this, cameraManager, scanMode); 171 | Log.e("hongliang1", "handler new成功!:"+handler); 172 | } 173 | 174 | initCrop(); 175 | } catch (IOException ioe) { 176 | Log.e(TAG,"hongliang", ioe); 177 | //弹出提示,报错 178 | ioe.printStackTrace(); 179 | listener.scanError(new Exception("相机打开出错,请检查是否被禁止了该权限!")); 180 | } catch (RuntimeException e) { 181 | Log.e(TAG, "hongliang", e); 182 | //弹出提示,报错 183 | e.printStackTrace(); 184 | listener.scanError(new Exception("相机打开出错,请检查是否被禁止了该权限!")); 185 | } 186 | } 187 | /** 188 | * 开关闪关灯 189 | */ 190 | public void switchLight(){ 191 | if(isOpenLight){ 192 | cameraManager.offLight(); 193 | }else{ 194 | cameraManager.openLight(); 195 | } 196 | isOpenLight=!isOpenLight; 197 | } 198 | public Handler getHandler() { 199 | return handler; 200 | } 201 | 202 | public CameraManager getCameraManager() { 203 | return cameraManager; 204 | } 205 | public Rect getCropRect() { 206 | return mCropRect; 207 | } 208 | /** 209 | * 扫描成功的结果回调 210 | * @param rawResult 211 | * @param bundle 212 | */ 213 | public void handleDecode(Result rawResult, Bundle bundle) { 214 | inactivityTimer.onActivity(); 215 | //扫描成功播放声音滴一下,可根据需要自行确定什么时候播 216 | beepManager.playBeepSoundAndVibrate(); 217 | bundle.putInt("width", mCropRect.width()); 218 | bundle.putInt("height", mCropRect.height()); 219 | bundle.putString("result", rawResult.getText()); 220 | listener.scanResult(rawResult, bundle); 221 | } 222 | public void handleDecodeError(Exception e){ 223 | listener.scanError(e); 224 | } 225 | /** 226 | * 初始化截取的矩形区域 227 | */ 228 | void initCrop() { 229 | int cameraWidth = cameraManager.getCameraResolution().y; 230 | int cameraHeight = cameraManager.getCameraResolution().x; 231 | 232 | /** 获取布局中扫描框的位置信息 */ 233 | int[] location = new int[2]; 234 | scanCropView.getLocationInWindow(location); 235 | 236 | int cropLeft = location[0]; 237 | int cropTop = location[1] - getStatusBarHeight(); 238 | 239 | int cropWidth = scanCropView.getWidth(); 240 | int cropHeight = scanCropView.getHeight(); 241 | 242 | /** 获取布局容器的宽高 */ 243 | int containerWidth = scanContainer.getWidth(); 244 | int containerHeight = scanContainer.getHeight(); 245 | 246 | /** 计算最终截取的矩形的左上角顶点x坐标 */ 247 | int x = cropLeft * cameraWidth / containerWidth; 248 | /** 计算最终截取的矩形的左上角顶点y坐标 */ 249 | int y = cropTop * cameraHeight / containerHeight; 250 | 251 | /** 计算最终截取的矩形的宽度 */ 252 | int width = cropWidth * cameraWidth / containerWidth; 253 | /** 计算最终截取的矩形的高度 */ 254 | int height = cropHeight * cameraHeight / containerHeight; 255 | 256 | /** 生成最终的截取的矩形 */ 257 | mCropRect = new Rect(x, y, width + x, height + y); 258 | } 259 | int getStatusBarHeight() { 260 | try { 261 | Class c = Class.forName("com.android.internal.R$dimen"); 262 | Object obj = c.newInstance(); 263 | Field field = c.getField("status_bar_height"); 264 | int x = Integer.parseInt(field.get(obj).toString()); 265 | return activity.getResources().getDimensionPixelSize(x); 266 | } catch (Exception e) { 267 | e.printStackTrace(); 268 | } 269 | return 0; 270 | } 271 | /** 272 | * 用于扫描本地图片二维码或者一维码 273 | * @param photo_path2 本地图片的所在位置 274 | * @return 275 | */ 276 | public void scanningImage(final String photo_path2) { 277 | if(TextUtils.isEmpty(photo_path2)){ 278 | listener.scanError(new Exception("photo url is null!")); 279 | } 280 | photoScanHandler=new PhotoScanHandler(this); 281 | new Thread(new Runnable() { 282 | 283 | @Override 284 | public void run() { 285 | //获取初始化的设置器 286 | Map hints = DecodeThread.getHints(); 287 | hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); 288 | 289 | // Hashtable hints = new Hashtable(); 290 | 291 | Bitmap bitmap= BitmapUtil.decodeBitmapFromPath(photo_path2,600,600); 292 | RGBLuminanceSource source = new RGBLuminanceSource(bitmap); 293 | BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source)); 294 | QRCodeReader reader = new QRCodeReader(); 295 | MultiFormatReader multiFormatReader=new MultiFormatReader(); 296 | try { 297 | Message msg=Message.obtain(); 298 | msg.what=PhotoScanHandler.PHOTODECODEOK; 299 | msg.obj = multiFormatReader.decode(bitmap1, hints); 300 | photoScanHandler.sendMessage(msg); 301 | } catch (Exception e) { 302 | Message msg=Message.obtain(); 303 | msg.what=PhotoScanHandler.PHOTODECODEERROR; 304 | msg.obj=new Exception("图片有误,或者图片模糊!"); 305 | photoScanHandler.sendMessage(msg); 306 | } 307 | } 308 | }).start(); 309 | } 310 | /** 311 | * 扫描一次后,如需再次扫描,请调用这个方法 312 | */ 313 | public void reScan(){ 314 | if(handler!=null){ 315 | handler.sendEmptyMessage(R.id.restart_preview); 316 | } 317 | } 318 | public boolean isScanning(){ 319 | if(handler!=null){ 320 | return handler.isScanning(); 321 | } 322 | return false; 323 | } 324 | 325 | } 326 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/camera/AutoFocusManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.liang.scancode.zxing.camera; 18 | 19 | import android.annotation.SuppressLint; 20 | import android.content.Context; 21 | import android.hardware.Camera; 22 | import android.os.AsyncTask; 23 | import android.os.Build; 24 | import android.util.Log; 25 | 26 | import java.util.ArrayList; 27 | import java.util.Collection; 28 | import java.util.concurrent.RejectedExecutionException; 29 | 30 | public class AutoFocusManager implements Camera.AutoFocusCallback { 31 | 32 | static final String TAG = AutoFocusManager.class.getSimpleName(); 33 | 34 | static final long AUTO_FOCUS_INTERVAL_MS = 2000L; 35 | static final Collection FOCUS_MODES_CALLING_AF; 36 | 37 | static { 38 | FOCUS_MODES_CALLING_AF = new ArrayList(2); 39 | FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_AUTO); 40 | FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_MACRO); 41 | } 42 | 43 | boolean stopped; 44 | boolean focusing; 45 | final boolean useAutoFocus; 46 | final Camera camera; 47 | AsyncTask outstandingTask; 48 | 49 | public AutoFocusManager(Context context, Camera camera) { 50 | this.camera = camera; 51 | String currentFocusMode = camera.getParameters().getFocusMode(); 52 | useAutoFocus = FOCUS_MODES_CALLING_AF.contains(currentFocusMode); 53 | Log.i(TAG, "Current focus mode '" + currentFocusMode + "'; use auto focus? " + useAutoFocus); 54 | start(); 55 | } 56 | 57 | @Override 58 | public synchronized void onAutoFocus(boolean success, Camera theCamera) { 59 | focusing = false; 60 | autoFocusAgainLater(); 61 | } 62 | 63 | @SuppressLint("NewApi") 64 | synchronized void autoFocusAgainLater() { 65 | if (!stopped && outstandingTask == null) { 66 | AutoFocusTask newTask = new AutoFocusTask(); 67 | try { 68 | if (Build.VERSION.SDK_INT >= 11) { 69 | newTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 70 | } else { 71 | newTask.execute(); 72 | } 73 | outstandingTask = newTask; 74 | } catch (RejectedExecutionException ree) { 75 | Log.w(TAG, "Could not request auto focus", ree); 76 | } 77 | } 78 | } 79 | 80 | public synchronized void start() { 81 | if (useAutoFocus) { 82 | outstandingTask = null; 83 | if (!stopped && !focusing) { 84 | try { 85 | camera.autoFocus(this); 86 | focusing = true; 87 | } catch (RuntimeException re) { 88 | // Have heard RuntimeException reported in Android 4.0.x+; 89 | // continue? 90 | Log.w(TAG, "Unexpected exception while focusing", re); 91 | // Try again later to keep cycle going 92 | autoFocusAgainLater(); 93 | } 94 | } 95 | } 96 | } 97 | 98 | synchronized void cancelOutstandingTask() { 99 | if (outstandingTask != null) { 100 | if (outstandingTask.getStatus() != AsyncTask.Status.FINISHED) { 101 | outstandingTask.cancel(true); 102 | } 103 | outstandingTask = null; 104 | } 105 | } 106 | 107 | public synchronized void stop() { 108 | stopped = true; 109 | if (useAutoFocus) { 110 | cancelOutstandingTask(); 111 | // Doesn't hurt to call this even if not focusing 112 | try { 113 | camera.cancelAutoFocus(); 114 | } catch (RuntimeException re) { 115 | // Have heard RuntimeException reported in Android 4.0.x+; 116 | // continue? 117 | Log.w(TAG, "Unexpected exception while cancelling focusing", re); 118 | } 119 | } 120 | } 121 | 122 | final class AutoFocusTask extends AsyncTask { 123 | @Override 124 | protected Object doInBackground(Object... voids) { 125 | try { 126 | Thread.sleep(AUTO_FOCUS_INTERVAL_MS); 127 | } catch (InterruptedException e) { 128 | // continue 129 | } 130 | start(); 131 | return null; 132 | } 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/camera/CameraConfigurationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.liang.scancode.zxing.camera; 17 | 18 | import android.annotation.SuppressLint; 19 | import android.content.Context; 20 | import android.graphics.Point; 21 | import android.hardware.Camera; 22 | import android.util.Log; 23 | import android.view.Display; 24 | import android.view.WindowManager; 25 | 26 | import java.util.ArrayList; 27 | import java.util.Collections; 28 | import java.util.Comparator; 29 | import java.util.Iterator; 30 | import java.util.List; 31 | 32 | /** 33 | * 34 | * 邮箱: 1076559197@qq.com | tauchen1990@gmail.com 35 | * 36 | * 作者: 陈涛 37 | * 38 | * 日期: 2014年8月20日 39 | * 40 | * 描述: 该类主要负责设置相机的参数信息,获取最佳的预览界面 41 | * 42 | */ 43 | public final class CameraConfigurationManager { 44 | 45 | static final String TAG = "CameraConfiguration"; 46 | 47 | static final int MIN_PREVIEW_PIXELS = 480 * 320; 48 | static final double MAX_ASPECT_DISTORTION = 0.15; 49 | 50 | final Context context; 51 | 52 | // 屏幕分辨率 53 | Point screenResolution; 54 | // 相机分辨率 55 | Point cameraResolution; 56 | 57 | public CameraConfigurationManager(Context context) { 58 | this.context = context; 59 | } 60 | 61 | public void initFromCameraParameters(Camera camera) { 62 | Camera.Parameters parameters = camera.getParameters(); 63 | WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 64 | Display display = manager.getDefaultDisplay(); 65 | Point theScreenResolution = new Point(); 66 | theScreenResolution = getDisplaySize(display); 67 | 68 | screenResolution = theScreenResolution; 69 | Log.i(TAG, "Screen resolution: " + screenResolution); 70 | 71 | /** 因为换成了竖屏显示,所以不替换屏幕宽高得出的预览图是变形的 */ 72 | Point screenResolutionForCamera = new Point(); 73 | screenResolutionForCamera.x = screenResolution.x; 74 | screenResolutionForCamera.y = screenResolution.y; 75 | 76 | if (screenResolution.x < screenResolution.y) { 77 | screenResolutionForCamera.x = screenResolution.y; 78 | screenResolutionForCamera.y = screenResolution.x; 79 | } 80 | 81 | cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera); 82 | Log.i(TAG, "Camera resolution x: " + cameraResolution.x); 83 | Log.i(TAG, "Camera resolution y: " + cameraResolution.y); 84 | } 85 | 86 | @SuppressWarnings("deprecation") 87 | @SuppressLint("NewApi") 88 | Point getDisplaySize(final Display display) { 89 | final Point point = new Point(); 90 | try { 91 | display.getSize(point); 92 | } catch (NoSuchMethodError ignore) { 93 | point.x = display.getWidth(); 94 | point.y = display.getHeight(); 95 | } 96 | return point; 97 | } 98 | 99 | public void setDesiredCameraParameters(Camera camera, boolean safeMode) { 100 | Camera.Parameters parameters = camera.getParameters(); 101 | 102 | if (parameters == null) { 103 | Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration."); 104 | return; 105 | } 106 | 107 | Log.i(TAG, "Initial camera parameters: " + parameters.flatten()); 108 | 109 | if (safeMode) { 110 | Log.w(TAG, "In camera config safe mode -- most settings will not be honored"); 111 | } 112 | 113 | parameters.setPreviewSize(cameraResolution.x, cameraResolution.y); 114 | camera.setParameters(parameters); 115 | 116 | Camera.Parameters afterParameters = camera.getParameters(); 117 | Camera.Size afterSize = afterParameters.getPreviewSize(); 118 | if (afterSize != null && (cameraResolution.x != afterSize.width || cameraResolution.y != afterSize.height)) { 119 | 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); 120 | cameraResolution.x = afterSize.width; 121 | cameraResolution.y = afterSize.height; 122 | } 123 | 124 | /** 设置相机预览为竖屏 */ 125 | camera.setDisplayOrientation(90); 126 | } 127 | 128 | public Point getCameraResolution() { 129 | return cameraResolution; 130 | } 131 | 132 | public Point getScreenResolution() { 133 | return screenResolution; 134 | } 135 | 136 | /** 137 | * 从相机支持的分辨率中计算出最适合的预览界面尺寸 138 | * 139 | * @param parameters 140 | * @param screenResolution 141 | * @return 142 | */ 143 | Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) { 144 | List rawSupportedSizes = parameters.getSupportedPreviewSizes(); 145 | if (rawSupportedSizes == null) { 146 | Log.w(TAG, "Device returned no supported preview sizes; using default"); 147 | Camera.Size defaultSize = parameters.getPreviewSize(); 148 | return new Point(defaultSize.width, defaultSize.height); 149 | } 150 | 151 | // Sort by size, descending 152 | List supportedPreviewSizes = new ArrayList(rawSupportedSizes); 153 | Collections.sort(supportedPreviewSizes, new Comparator() { 154 | @Override 155 | public int compare(Camera.Size a, Camera.Size b) { 156 | int aPixels = a.height * a.width; 157 | int bPixels = b.height * b.width; 158 | if (bPixels < aPixels) { 159 | return -1; 160 | } 161 | if (bPixels > aPixels) { 162 | return 1; 163 | } 164 | return 0; 165 | } 166 | }); 167 | 168 | if (Log.isLoggable(TAG, Log.INFO)) { 169 | StringBuilder previewSizesString = new StringBuilder(); 170 | for (Camera.Size supportedPreviewSize : supportedPreviewSizes) { 171 | previewSizesString.append(supportedPreviewSize.width).append('x').append(supportedPreviewSize.height).append(' '); 172 | } 173 | Log.i(TAG, "Supported preview sizes: " + previewSizesString); 174 | } 175 | 176 | double screenAspectRatio = (double) screenResolution.x / (double) screenResolution.y; 177 | 178 | // Remove sizes that are unsuitable 179 | Iterator it = supportedPreviewSizes.iterator(); 180 | while (it.hasNext()) { 181 | Camera.Size supportedPreviewSize = it.next(); 182 | int realWidth = supportedPreviewSize.width; 183 | int realHeight = supportedPreviewSize.height; 184 | if (realWidth * realHeight < MIN_PREVIEW_PIXELS) { 185 | it.remove(); 186 | continue; 187 | } 188 | 189 | boolean isCandidatePortrait = realWidth < realHeight; 190 | int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth; 191 | int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight; 192 | 193 | double aspectRatio = (double) maybeFlippedWidth / (double) maybeFlippedHeight; 194 | double distortion = Math.abs(aspectRatio - screenAspectRatio); 195 | if (distortion > MAX_ASPECT_DISTORTION) { 196 | it.remove(); 197 | continue; 198 | } 199 | 200 | if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) { 201 | Point exactPoint = new Point(realWidth, realHeight); 202 | Log.i(TAG, "Found preview size exactly matching screen size: " + exactPoint); 203 | return exactPoint; 204 | } 205 | } 206 | 207 | // If no exact match, use largest preview size. This was not a great 208 | // idea on older devices because 209 | // of the additional computation needed. We're likely to get here on 210 | // newer Android 4+ devices, where 211 | // the CPU is much more powerful. 212 | if (!supportedPreviewSizes.isEmpty()) { 213 | Camera.Size largestPreview = supportedPreviewSizes.get(0); 214 | Point largestSize = new Point(largestPreview.width, largestPreview.height); 215 | Log.i(TAG, "Using largest suitable preview size: " + largestSize); 216 | return largestSize; 217 | } 218 | 219 | // If there is nothing at shouquan_ic_all suitable, return current preview size 220 | Camera.Size defaultPreview = parameters.getPreviewSize(); 221 | Point defaultSize = new Point(defaultPreview.width, defaultPreview.height); 222 | Log.i(TAG, "No suitable preview sizes, using default: " + defaultSize); 223 | 224 | return defaultSize; 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/camera/CameraManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.liang.scancode.zxing.camera; 18 | 19 | import android.content.Context; 20 | import android.graphics.Point; 21 | import android.hardware.Camera; 22 | import android.hardware.Camera.Parameters; 23 | import android.hardware.Camera.Size; 24 | import android.os.Handler; 25 | import android.util.Log; 26 | import android.view.SurfaceHolder; 27 | 28 | import java.io.IOException; 29 | 30 | import com.liang.scancode.zxing.camera.open.OpenCameraInterface; 31 | 32 | /** 33 | * This object wraps the Camera service object and expects to be the only one 34 | * talking to it. The implementation encapsulates the steps needed to take 35 | * preview-sized images, which are used for both preview and decoding. 36 | * 37 | * @author dswitkin@google.com (Daniel Switkin) 38 | */ 39 | public class CameraManager { 40 | 41 | static final String TAG = CameraManager.class.getSimpleName(); 42 | 43 | final Context context; 44 | final CameraConfigurationManager configManager; 45 | Camera camera; 46 | AutoFocusManager autoFocusManager; 47 | 48 | boolean initialized; 49 | boolean previewing; 50 | 51 | 52 | 53 | int requestedCameraId = -1; 54 | /** 55 | * Preview frames are delivered here, which we pass on to the registered 56 | * handler. Make sure to clear the handler so it will only receive one 57 | * message. 58 | */ 59 | final PreviewCallback previewCallback; 60 | 61 | public CameraManager(Context context) { 62 | this.context = context; 63 | this.configManager = new CameraConfigurationManager(context); 64 | previewCallback = new PreviewCallback(configManager); 65 | } 66 | 67 | /** 68 | * Opens the camera driver and initializes the hardware parameters. 69 | * 70 | * @param holder 71 | * The surface object which the camera will draw preview frames 72 | * into. 73 | * @throws IOException 74 | * Indicates the camera driver failed to open. 75 | */ 76 | public synchronized void openDriver(SurfaceHolder holder) throws IOException { 77 | Camera theCamera = camera; 78 | if (theCamera == null) { 79 | 80 | if (requestedCameraId >= 0) { 81 | theCamera = OpenCameraInterface.open(requestedCameraId); 82 | } else { 83 | theCamera = OpenCameraInterface.open(); 84 | } 85 | 86 | if (theCamera == null) { 87 | throw new IOException(); 88 | } 89 | camera = theCamera; 90 | } 91 | theCamera.setPreviewDisplay(holder); 92 | 93 | if (!initialized) { 94 | initialized = true; 95 | configManager.initFromCameraParameters(theCamera); 96 | } 97 | 98 | Parameters parameters = theCamera.getParameters(); 99 | String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save 100 | // these, 101 | // temporarily 102 | try { 103 | configManager.setDesiredCameraParameters(theCamera, false); 104 | } catch (RuntimeException re) { 105 | // Driver failed 106 | Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters"); 107 | Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened); 108 | // Reset: 109 | if (parametersFlattened != null) { 110 | parameters = theCamera.getParameters(); 111 | parameters.unflatten(parametersFlattened); 112 | try { 113 | theCamera.setParameters(parameters); 114 | configManager.setDesiredCameraParameters(theCamera, true); 115 | } catch (RuntimeException re2) { 116 | // Well, darn. Give up 117 | Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration"); 118 | } 119 | } 120 | } 121 | 122 | } 123 | 124 | public synchronized boolean isOpen() { 125 | return camera != null; 126 | } 127 | 128 | /** 129 | * Closes the camera driver if still in use. 130 | */ 131 | public synchronized void closeDriver() { 132 | if (camera != null) { 133 | camera.release(); 134 | camera = null; 135 | // Make sure to clear these each time we close the camera, so that 136 | // any scanning rect 137 | // requested by intent is forgotten. 138 | } 139 | } 140 | 141 | /** 142 | * Asks the camera hardware to begin drawing preview frames to the screen. 143 | */ 144 | public synchronized void startPreview() { 145 | Camera theCamera = camera; 146 | if (theCamera != null && !previewing) { 147 | theCamera.startPreview(); 148 | previewing = true; 149 | autoFocusManager = new AutoFocusManager(context, camera); 150 | } 151 | } 152 | 153 | /** 154 | * Tells the camera to stop drawing preview frames. 155 | */ 156 | public synchronized void stopPreview() { 157 | if (autoFocusManager != null) { 158 | autoFocusManager.stop(); 159 | autoFocusManager = null; 160 | } 161 | if (camera != null && previewing) { 162 | camera.stopPreview(); 163 | previewCallback.setHandler(null, 0); 164 | previewing = false; 165 | } 166 | } 167 | 168 | /** 169 | * A single preview frame will be returned to the handler supplied. The data 170 | * will arrive as byte[] in the message.obj field, with width and height 171 | * encoded as message.arg1 and message.arg2, respectively. 172 | * 173 | * @param handler 174 | * The handler to send the message to. 175 | * @param message 176 | * The what field of the message to be sent. 177 | */ 178 | public synchronized void requestPreviewFrame(Handler handler, int message) { 179 | Camera theCamera = camera; 180 | if (theCamera != null && previewing) { 181 | previewCallback.setHandler(handler, message); 182 | theCamera.setOneShotPreviewCallback(previewCallback); 183 | } 184 | } 185 | 186 | /** 187 | * Allows third party apps to specify the camera ID, rather than determine 188 | * it automatically based on available cameras and their orientation. 189 | * 190 | * @param cameraId 191 | * camera ID of the camera to use. A negative value means 192 | * "no preference". 193 | */ 194 | public synchronized void setManualCameraId(int cameraId) { 195 | requestedCameraId = cameraId; 196 | } 197 | 198 | /** 199 | * 获取相机分辨率 200 | * 201 | * @return 202 | */ 203 | public Point getCameraResolution() { 204 | return configManager.getCameraResolution(); 205 | } 206 | 207 | public Size getPreviewSize() { 208 | if (null != camera) { 209 | return camera.getParameters().getPreviewSize(); 210 | } 211 | return null; 212 | } 213 | 214 | /** 215 | * 打开闪光灯 216 | */ 217 | public void openLight() { 218 | if (camera != null) { 219 | Parameters parameter = camera.getParameters(); 220 | parameter.setFlashMode(Parameters.FLASH_MODE_TORCH); 221 | camera.setParameters(parameter); 222 | } 223 | } 224 | /** 225 | * 关闭闪光灯 226 | */ 227 | public void offLight() { 228 | if (camera != null) { 229 | Parameters parameter = camera.getParameters(); 230 | parameter.setFlashMode(Parameters.FLASH_MODE_OFF); 231 | camera.setParameters(parameter); 232 | } 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/camera/PreviewCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.liang.scancode.zxing.camera; 18 | 19 | import android.graphics.Point; 20 | import android.hardware.Camera; 21 | import android.os.Handler; 22 | import android.os.Message; 23 | import android.util.Log; 24 | 25 | public class PreviewCallback implements Camera.PreviewCallback { 26 | 27 | static final String TAG = PreviewCallback.class.getSimpleName(); 28 | 29 | final CameraConfigurationManager configManager; 30 | Handler previewHandler; 31 | int previewMessage; 32 | 33 | public PreviewCallback(CameraConfigurationManager configManager) { 34 | this.configManager = configManager; 35 | } 36 | 37 | public void setHandler(Handler previewHandler, int previewMessage) { 38 | this.previewHandler = previewHandler; 39 | this.previewMessage = previewMessage; 40 | } 41 | 42 | @Override 43 | public void onPreviewFrame(byte[] data, Camera camera) { 44 | Point cameraResolution = configManager.getCameraResolution(); 45 | Handler thePreviewHandler = previewHandler; 46 | if (cameraResolution != null && thePreviewHandler != null) { 47 | Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x, cameraResolution.y, data); 48 | message.sendToTarget(); 49 | previewHandler = null; 50 | } else { 51 | Log.d(TAG, "Got preview callback, but no handler or resolution available"); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/camera/open/OpenCameraInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.liang.scancode.zxing.camera.open; 18 | 19 | import android.hardware.Camera; 20 | import android.util.Log; 21 | 22 | public class OpenCameraInterface { 23 | 24 | static final String TAG = OpenCameraInterface.class.getName(); 25 | 26 | /** 27 | * Opens the requested camera with {@link Camera#open(int)}, if one exists. 28 | * 29 | * @param cameraId 30 | * camera ID of the camera to use. A negative value means 31 | * "no preference" 32 | * @return handle to {@link Camera} that was opened 33 | */ 34 | public static Camera open(int cameraId) { 35 | 36 | int numCameras = Camera.getNumberOfCameras(); 37 | if (numCameras == 0) { 38 | Log.w(TAG, "No cameras!"); 39 | return null; 40 | } 41 | 42 | boolean explicitRequest = cameraId >= 0; 43 | 44 | if (!explicitRequest) { 45 | // Select a camera if no explicit camera requested 46 | int index = 0; 47 | while (index < numCameras) { 48 | Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); 49 | Camera.getCameraInfo(index, cameraInfo); 50 | if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { 51 | break; 52 | } 53 | index++; 54 | } 55 | 56 | cameraId = index; 57 | } 58 | 59 | Camera camera; 60 | if (cameraId < numCameras) { 61 | Log.i(TAG, "Opening camera #" + cameraId); 62 | camera = Camera.open(cameraId); 63 | } else { 64 | if (explicitRequest) { 65 | Log.w(TAG, "Requested camera does not exist: " + cameraId); 66 | camera = null; 67 | } else { 68 | Log.i(TAG, "No camera facing back; returning camera #0"); 69 | camera = Camera.open(0); 70 | } 71 | } 72 | 73 | return camera; 74 | } 75 | 76 | /** 77 | * Opens a rear-facing camera with {@link Camera#open(int)}, if one exists, 78 | * or opens camera 0. 79 | * 80 | * @return handle to {@link Camera} that was opened 81 | */ 82 | public static Camera open() { 83 | return open(-1); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/decode/DecodeFormatManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.liang.scancode.zxing.decode; 18 | 19 | import com.google.zxing.BarcodeFormat; 20 | 21 | import java.util.Collection; 22 | import java.util.EnumSet; 23 | import java.util.Set; 24 | 25 | public class DecodeFormatManager { 26 | 27 | // 1D解码 28 | static final Set PRODUCT_FORMATS; 29 | static final Set INDUSTRIAL_FORMATS; 30 | static final Set ONE_D_FORMATS; 31 | 32 | // 二维码解码 33 | static final Set QR_CODE_FORMATS; 34 | 35 | static { 36 | PRODUCT_FORMATS = EnumSet.of(BarcodeFormat.UPC_A, BarcodeFormat.UPC_E, BarcodeFormat.EAN_13, BarcodeFormat.EAN_8, BarcodeFormat.RSS_14, BarcodeFormat.RSS_EXPANDED); 37 | INDUSTRIAL_FORMATS = EnumSet.of(BarcodeFormat.CODE_39, BarcodeFormat.CODE_93, BarcodeFormat.CODE_128, BarcodeFormat.ITF, BarcodeFormat.CODABAR); 38 | ONE_D_FORMATS = EnumSet.copyOf(PRODUCT_FORMATS); 39 | ONE_D_FORMATS.addAll(INDUSTRIAL_FORMATS); 40 | 41 | QR_CODE_FORMATS = EnumSet.of(BarcodeFormat.QR_CODE); 42 | } 43 | 44 | public static Collection getQrCodeFormats() { 45 | return QR_CODE_FORMATS; 46 | } 47 | 48 | public static Collection getBarCodeFormats() { 49 | return ONE_D_FORMATS; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/decode/DecodeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.liang.scancode.zxing.decode; 18 | 19 | import android.graphics.Bitmap; 20 | import android.graphics.Rect; 21 | import android.hardware.Camera.Size; 22 | import android.os.Bundle; 23 | import android.os.Handler; 24 | import android.os.Looper; 25 | import android.os.Message; 26 | 27 | import com.google.zxing.BinaryBitmap; 28 | import com.google.zxing.DecodeHintType; 29 | import com.google.zxing.MultiFormatReader; 30 | import com.google.zxing.PlanarYUVLuminanceSource; 31 | import com.google.zxing.ReaderException; 32 | import com.google.zxing.Result; 33 | import com.google.zxing.common.HybridBinarizer; 34 | import com.liang.scancode.R; 35 | import com.liang.scancode.zxing.ScanManager; 36 | 37 | import java.io.ByteArrayOutputStream; 38 | import java.util.Map; 39 | 40 | public class DecodeHandler extends Handler { 41 | 42 | final ScanManager scanManager; 43 | final MultiFormatReader multiFormatReader; 44 | boolean running = true; 45 | 46 | public DecodeHandler(ScanManager scanManager, Map hints) { 47 | multiFormatReader = new MultiFormatReader(); 48 | multiFormatReader.setHints(hints); 49 | this.scanManager = scanManager; 50 | } 51 | 52 | @Override 53 | public void handleMessage(Message message) { 54 | if (!running) { 55 | return; 56 | } 57 | switch (message.what) { 58 | case R.id.decode: 59 | decode((byte[]) message.obj, message.arg1, message.arg2); 60 | break; 61 | case R.id.quit: 62 | running = false; 63 | Looper.myLooper().quit(); 64 | break; 65 | } 66 | } 67 | 68 | /** 69 | * Decode the data within the viewfinder rectangle, and time how long it 70 | * took. For efficiency, reuse the same reader objects from one decode to 71 | * the next. 72 | * 73 | * @param data 74 | * The YUV preview frame. 75 | * @param width 76 | * The width of the preview frame. 77 | * @param height 78 | * The height of the preview frame. 79 | */ 80 | void decode(byte[] data, int width, int height) { 81 | Size size = scanManager.getCameraManager().getPreviewSize(); 82 | 83 | // 这里需要将获取的data翻转一下,因为相机默认拿的的横屏的数据 84 | byte[] rotatedData = new byte[data.length]; 85 | for (int y = 0; y < size.height; y++) { 86 | for (int x = 0; x < size.width; x++) 87 | rotatedData[x * size.height + size.height - y - 1] = data[x + y * size.width]; 88 | } 89 | 90 | // 宽高也要调整 91 | int tmp = size.width; 92 | size.width = size.height; 93 | size.height = tmp; 94 | 95 | Result rawResult = null; 96 | PlanarYUVLuminanceSource source = buildLuminanceSource(rotatedData, size.width, size.height); 97 | if (source != null) { 98 | BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); 99 | try { 100 | rawResult = multiFormatReader.decodeWithState(bitmap); 101 | } catch (ReaderException re) { 102 | // continue 103 | } finally { 104 | multiFormatReader.reset(); 105 | } 106 | } 107 | 108 | Handler handler = scanManager.getHandler(); 109 | if (rawResult != null) { 110 | // Don't log the barcode contents for security. 111 | if (handler != null) { 112 | Message message = Message.obtain(handler, R.id.decode_succeeded, rawResult); 113 | Bundle bundle = new Bundle(); 114 | bundleThumbnail(source, bundle); 115 | message.setData(bundle); 116 | message.sendToTarget(); 117 | } 118 | } else { 119 | if (handler != null) { 120 | Message message = Message.obtain(handler, R.id.decode_failed); 121 | message.sendToTarget(); 122 | } 123 | } 124 | 125 | } 126 | 127 | static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) { 128 | int[] pixels = source.renderThumbnail(); 129 | int width = source.getThumbnailWidth(); 130 | int height = source.getThumbnailHeight(); 131 | Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888); 132 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 133 | bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out); 134 | bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray()); 135 | } 136 | 137 | /** 138 | * A factory method to build the appropriate LuminanceSource object based on 139 | * the format of the preview buffers, as described by Camera.Parameters. 140 | * 141 | * @param data 142 | * A preview frame. 143 | * @param width 144 | * The width of the image. 145 | * @param height 146 | * The height of the image. 147 | * @return A PlanarYUVLuminanceSource instance. 148 | */ 149 | public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) { 150 | Rect rect = scanManager.getCropRect(); 151 | if (rect == null) { 152 | return null; 153 | } 154 | // Go ahead and assume it's YUV rather than die. 155 | return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect.height(), false); 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/decode/DecodeThread.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.liang.scancode.zxing.decode; 18 | 19 | import android.os.Handler; 20 | import android.os.Looper; 21 | 22 | import com.google.zxing.BarcodeFormat; 23 | import com.google.zxing.DecodeHintType; 24 | 25 | import java.util.ArrayList; 26 | import java.util.Collection; 27 | import java.util.EnumMap; 28 | import java.util.EnumSet; 29 | import java.util.Map; 30 | import java.util.concurrent.CountDownLatch; 31 | 32 | import com.liang.scancode.zxing.ScanManager; 33 | 34 | /** 35 | * This thread does shouquan_ic_all the heavy lifting of decoding the images. 36 | * 37 | * @author dswitkin@google.com (Daniel Switkin) 38 | */ 39 | public class DecodeThread extends Thread { 40 | 41 | public static final String BARCODE_BITMAP = "barcode_bitmap"; 42 | 43 | public static final int BARCODE_MODE = 0X100; 44 | public static final int QRCODE_MODE = 0X200; 45 | public static final int ALL_MODE = 0X300; 46 | 47 | final ScanManager scanManager; 48 | static Map hints; 49 | Handler handler; 50 | final CountDownLatch handlerInitLatch; 51 | 52 | public DecodeThread(ScanManager scanManager, int decodeMode) { 53 | 54 | this.scanManager = scanManager; 55 | handlerInitLatch = new CountDownLatch(1); 56 | 57 | hints = new EnumMap(DecodeHintType.class); 58 | 59 | Collection decodeFormats = new ArrayList(); 60 | decodeFormats.addAll(EnumSet.of(BarcodeFormat.AZTEC)); 61 | decodeFormats.addAll(EnumSet.of(BarcodeFormat.PDF_417)); 62 | 63 | switch (decodeMode) { 64 | case BARCODE_MODE: 65 | decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats()); 66 | break; 67 | 68 | case QRCODE_MODE: 69 | decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats()); 70 | break; 71 | 72 | case ALL_MODE: 73 | decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats()); 74 | decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats()); 75 | break; 76 | 77 | default: 78 | break; 79 | } 80 | 81 | hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats); 82 | } 83 | 84 | public Handler getHandler() { 85 | try { 86 | handlerInitLatch.await(); 87 | } catch (InterruptedException ie) { 88 | // continue? 89 | } 90 | return handler; 91 | } 92 | 93 | @Override 94 | public void run() { 95 | Looper.prepare(); 96 | handler = new DecodeHandler(scanManager, hints); 97 | handlerInitLatch.countDown(); 98 | Looper.loop(); 99 | } 100 | 101 | public static Map getHints() { 102 | return hints; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/decode/PhotoScanHandler.java: -------------------------------------------------------------------------------- 1 | package com.liang.scancode.zxing.decode; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.os.Message; 6 | 7 | import com.google.zxing.Result; 8 | 9 | import com.liang.scancode.zxing.ScanManager; 10 | 11 | public class PhotoScanHandler extends Handler{ 12 | public final static int PHOTODECODEERROR=0; 13 | public final static int PHOTODECODEOK=1; 14 | ScanManager scanManager; 15 | public PhotoScanHandler(ScanManager scanManager) { 16 | this.scanManager=scanManager; 17 | } 18 | @Override 19 | public void handleMessage(Message message) { 20 | 21 | switch (message.what) { 22 | case PHOTODECODEERROR: 23 | scanManager.handleDecodeError((Exception)message.obj); 24 | break; 25 | case PHOTODECODEOK: 26 | Bundle bundle = message.getData(); 27 | scanManager.handleDecode((Result) message.obj, bundle); 28 | break; 29 | default: 30 | break; 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/decode/RGBLuminanceSource.java: -------------------------------------------------------------------------------- 1 | package com.liang.scancode.zxing.decode; 2 | 3 | /* 4 | * Copyright 2009 ZXing authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | 20 | import android.graphics.Bitmap; 21 | import android.graphics.BitmapFactory; 22 | 23 | import com.google.zxing.LuminanceSource; 24 | 25 | import java.io.FileNotFoundException; 26 | 27 | /** 28 | * This class is used to help decode images from files which arrive as RGB data 29 | * from Android bitmaps. It does not support cropping or rotation. 30 | * 31 | * @author dswitkin@google.com (Daniel Switkin) 32 | */ 33 | public final class RGBLuminanceSource extends LuminanceSource { 34 | final byte[] luminances; 35 | 36 | public RGBLuminanceSource(String path) throws FileNotFoundException { 37 | this(loadBitmap(path)); 38 | } 39 | 40 | public RGBLuminanceSource(Bitmap bitmap) { 41 | super(bitmap.getWidth(), bitmap.getHeight()); 42 | int width = bitmap.getWidth(); 43 | int height = bitmap.getHeight(); 44 | int[] pixels = new int[width * height]; 45 | bitmap.getPixels(pixels, 0, width, 0, 0, width, height); 46 | // In order to measure pure decoding speed, we convert the entire image 47 | // to a greyscale array 48 | // up front, which is the same as the Y channel of the 49 | // YUVLuminanceSource in the real app. 50 | luminances = new byte[width * height]; 51 | for (int y = 0; y < height; y++) { 52 | int offset = y * width; 53 | for (int x = 0; x < width; x++) { 54 | int pixel = pixels[offset + x]; 55 | int r = (pixel >> 16) & 0xff; 56 | int g = (pixel >> 8) & 0xff; 57 | int b = pixel & 0xff; 58 | if (r == g && g == b) { 59 | // Image is already greyscale, so pick any channel. 60 | luminances[offset + x] = (byte) r; 61 | } else { 62 | // Calculate luminance cheaply, favoring green. 63 | luminances[offset + x] = (byte) ((r + g + g + b) >> 2); 64 | } 65 | } 66 | } 67 | } 68 | 69 | @Override 70 | public byte[] getRow(int y, byte[] row) { 71 | if (y < 0 || y >= getHeight()) { 72 | throw new IllegalArgumentException( 73 | "Requested row is outside the image: " + y); 74 | } 75 | int width = getWidth(); 76 | if (row == null || row.length < width) { 77 | row = new byte[width]; 78 | } 79 | System.arraycopy(luminances, y * width, row, 0, width); 80 | return row; 81 | } 82 | 83 | // Since this class does not support cropping, the underlying byte array 84 | // already contains 85 | // exactly what the caller is asking for, so give it to them without a copy. 86 | @Override 87 | public byte[] getMatrix() { 88 | return luminances; 89 | } 90 | 91 | static Bitmap loadBitmap(String path) throws FileNotFoundException { 92 | Bitmap bitmap = BitmapFactory.decodeFile(path); 93 | if (bitmap == null) { 94 | throw new FileNotFoundException("Couldn't open " + path); 95 | } 96 | return bitmap; 97 | } 98 | } -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/decode/Utils.java: -------------------------------------------------------------------------------- 1 | package com.liang.scancode.zxing.decode; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.ContentUris; 5 | import android.content.Context; 6 | import android.database.Cursor; 7 | import android.graphics.Bitmap; 8 | import android.graphics.Matrix; 9 | import android.media.ExifInterface; 10 | import android.net.Uri; 11 | import android.os.Build; 12 | import android.os.Environment; 13 | import android.provider.DocumentsContract; 14 | import android.provider.MediaStore; 15 | 16 | import java.io.IOException; 17 | 18 | public class Utils { 19 | @SuppressLint("NewApi") 20 | public static String getPath(final Context context, final Uri uri) { 21 | 22 | final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; 23 | 24 | // DocumentProvider 25 | if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { 26 | // ExternalStorageProvider 27 | if (isExternalStorageDocument(uri)) { 28 | final String docId = DocumentsContract.getDocumentId(uri); 29 | final String[] split = docId.split(":"); 30 | final String type = split[0]; 31 | 32 | if ("primary".equalsIgnoreCase(type)) { 33 | return Environment.getExternalStorageDirectory() + "/" 34 | + split[1]; 35 | } 36 | // TODO handle non-primary volumes 37 | } 38 | // DownloadsProvider 39 | else if (isDownloadsDocument(uri)) { 40 | 41 | final String id = DocumentsContract.getDocumentId(uri); 42 | final Uri contentUri = ContentUris.withAppendedId( 43 | Uri.parse("content://downloads/public_downloads"), 44 | Long.valueOf(id)); 45 | 46 | return getDataColumn(context, contentUri, null, null); 47 | } 48 | // MediaProvider 49 | else if (isMediaDocument(uri)) { 50 | final String docId = DocumentsContract.getDocumentId(uri); 51 | final String[] split = docId.split(":"); 52 | final String type = split[0]; 53 | 54 | Uri contentUri = null; 55 | if ("image".equals(type)) { 56 | contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 57 | } else if ("video".equals(type)) { 58 | contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; 59 | } else if ("audio".equals(type)) { 60 | contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; 61 | } 62 | 63 | final String selection = "_id=?"; 64 | final String[] selectionArgs = new String[]{split[1]}; 65 | 66 | return getDataColumn(context, contentUri, selection, 67 | selectionArgs); 68 | } 69 | } 70 | // MediaStore (and general) 71 | else if ("content".equalsIgnoreCase(uri.getScheme())) { 72 | return getDataColumn(context, uri, null, null); 73 | } 74 | // File 75 | else if ("file".equalsIgnoreCase(uri.getScheme())) { 76 | return uri.getPath(); 77 | } 78 | 79 | return null; 80 | } 81 | 82 | public static String getDataColumn(Context context, Uri uri, 83 | String selection, String[] selectionArgs) { 84 | 85 | Cursor cursor = null; 86 | final String column = "_data"; 87 | final String[] projection = {column}; 88 | 89 | try { 90 | cursor = context.getContentResolver().query(uri, projection, 91 | selection, selectionArgs, null); 92 | if (cursor != null && cursor.moveToFirst()) { 93 | final int column_index = cursor.getColumnIndexOrThrow(column); 94 | return cursor.getString(column_index); 95 | } 96 | } finally { 97 | if (cursor != null) 98 | cursor.close(); 99 | } 100 | return null; 101 | } 102 | 103 | public static boolean isExternalStorageDocument(Uri uri) { 104 | return "com.android.externalstorage.documents".equals(uri 105 | .getAuthority()); 106 | } 107 | 108 | public static boolean isDownloadsDocument(Uri uri) { 109 | return "com.android.providers.downloads.documents".equals(uri 110 | .getAuthority()); 111 | } 112 | 113 | public static boolean isMediaDocument(Uri uri) { 114 | return "com.android.providers.media.documents".equals(uri 115 | .getAuthority()); 116 | } 117 | /** 118 | * 读取图片属性:旋转的角度 119 | * @param path 图片绝对路径 120 | * @return degree旋转的角度 121 | */ 122 | public static int readPictureDegree(String path) { 123 | int degree = 0; 124 | try { 125 | ExifInterface exifInterface = new ExifInterface(path); 126 | int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); 127 | switch (orientation) { 128 | case ExifInterface.ORIENTATION_ROTATE_90: 129 | degree = 90; 130 | break; 131 | case ExifInterface.ORIENTATION_ROTATE_180: 132 | degree = 180; 133 | break; 134 | case ExifInterface.ORIENTATION_ROTATE_270: 135 | degree = 270; 136 | break; 137 | } 138 | } catch (IOException e) { 139 | e.printStackTrace(); 140 | } 141 | return degree; 142 | } 143 | /* 144 | * 旋转图片 145 | * @param angle 146 | * @param bitmap 147 | * @return Bitmap 148 | */ 149 | public static Bitmap rotaingImageView(int angle , Bitmap bitmap) { 150 | //旋转图片 动作 151 | Matrix matrix = new Matrix();; 152 | matrix.postRotate(angle); 153 | System.out.println("angle2=" + angle); 154 | // 创建新的图片 155 | Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, 156 | bitmap.getWidth(), bitmap.getHeight(), matrix, true); 157 | return resizedBitmap; 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/encode/EncodingHandler.java: -------------------------------------------------------------------------------- 1 | package com.liang.scancode.zxing.encode; 2 | 3 | import android.graphics.Bitmap; 4 | import android.util.Log; 5 | 6 | import com.google.zxing.BarcodeFormat; 7 | import com.google.zxing.EncodeHintType; 8 | import com.google.zxing.MultiFormatWriter; 9 | import com.google.zxing.WriterException; 10 | import com.google.zxing.common.BitMatrix; 11 | import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; 12 | 13 | import java.io.UnsupportedEncodingException; 14 | import java.util.Hashtable; 15 | 16 | /** 17 | * @author 刘红亮 2015年4月29日 下午3:27:08 18 | * 用于生成二维码 19 | */ 20 | public final class EncodingHandler { 21 | static final int BLACK = 0xff000000; 22 | static final int WHITE = 0xFFFFFFFF; 23 | /** 24 | * 生成二维码图片 25 | * 26 | * @param str 要往二维码中写入的内容,需要utf-8格式 27 | * @param widthAndHeight 图片的宽高,正方形 28 | * @return 返回一个二维码bitmap 29 | * @throws WriterException 30 | * @throws UnsupportedEncodingException 31 | */ 32 | public static Bitmap create2Code(String str, int widthAndHeight) throws WriterException, UnsupportedEncodingException { 33 | BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight, getEncodeHintMap()); 34 | return BitMatrixToBitmap(matrix); 35 | } 36 | 37 | /** 38 | * 生成条形码图片 39 | * @param str 要往二维码中写入的内容,需要utf-8格式 40 | * @param width 图片的宽 41 | * @param height 图片的高 42 | * @return 返回一个条形bitmap 43 | * @throws Exception 44 | */ 45 | public static Bitmap createBarCode(String str, Integer width, Integer height) throws Exception{ 46 | BitMatrix bitMatrix = new MultiFormatWriter().encode(str, BarcodeFormat.CODE_128, width, height, getEncodeHintMap()); 47 | return BitMatrixToBitmap(bitMatrix); 48 | } 49 | /** 50 | * 获得设置好的编码参数 51 | * @return 编码参数 52 | */ 53 | private static Hashtable getEncodeHintMap() { 54 | Hashtable hints= new Hashtable(); 55 | //设置编码为utf-8 56 | hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); 57 | // 设置QR二维码的纠错级别——这里选择最高H级别 58 | hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); 59 | return hints; 60 | } 61 | /** 62 | * BitMatrix转换成Bitmap 63 | * 64 | * @param matrix 65 | * @return 66 | */ 67 | private static Bitmap BitMatrixToBitmap(BitMatrix matrix) { 68 | int width = matrix.getWidth(); 69 | int height = matrix.getHeight(); 70 | int[] pixels = new int[width * height]; 71 | for (int y = 0; y < height; y++) { 72 | int offset = y * width; 73 | for (int x = 0; x < width; x++) { 74 | if(matrix.get(x,y)){ 75 | pixels[offset + x] =BLACK; //上面图案的颜色 76 | }else{ 77 | pixels[offset + x] =WHITE;//底色 78 | } 79 | } 80 | } 81 | Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 82 | bitmap.setPixels(pixels, 0, width, 0, 0, width, height); 83 | Log.e("hongliang","width:"+bitmap.getWidth()+" height:"+bitmap.getHeight()); 84 | return bitmap; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/utils/AppliationUtil.java: -------------------------------------------------------------------------------- 1 | package com.liang.scancode.zxing.utils; 2 | 3 | /** 4 | * Created by 刘红亮 on 2015/7/23 22:35. 5 | */ 6 | public class AppliationUtil { 7 | //应用程序最大可用内存 8 | public static int MAX_MEMORY = ((int) Runtime.getRuntime().maxMemory())/1024/1024; 9 | //应用程序已获得内存 10 | public static long TOTAL_MEMORY = ((int) Runtime.getRuntime().totalMemory())/1024/1024; 11 | //应用程序已获得内存中未使用内存 12 | public static long FREE_MEMORY = ((int) Runtime.getRuntime().freeMemory())/1024/1024; 13 | 14 | 15 | 16 | } -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/utils/BeepManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.liang.scancode.zxing.utils; 18 | 19 | import android.app.Activity; 20 | import android.content.Context; 21 | import android.content.SharedPreferences; 22 | import android.content.res.AssetFileDescriptor; 23 | import android.media.AudioManager; 24 | import android.media.MediaPlayer; 25 | import android.os.Vibrator; 26 | import android.preference.PreferenceManager; 27 | import android.util.Log; 28 | 29 | import com.liang.scancode.R; 30 | 31 | import java.io.Closeable; 32 | import java.io.IOException; 33 | 34 | 35 | 36 | /** 37 | */ 38 | public class BeepManager implements MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, Closeable { 39 | 40 | static final String TAG = BeepManager.class.getSimpleName(); 41 | 42 | static final float BEEP_VOLUME = 0.10f; 43 | static final long VIBRATE_DURATION = 200L; 44 | 45 | final Activity activity; 46 | MediaPlayer mediaPlayer; 47 | boolean playBeep; 48 | boolean vibrate; 49 | 50 | public BeepManager(Activity activity) { 51 | this.activity = activity; 52 | this.mediaPlayer = null; 53 | updatePrefs(); 54 | } 55 | 56 | synchronized void updatePrefs() { 57 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); 58 | playBeep = shouldBeep(prefs, activity); 59 | vibrate = true; 60 | if (playBeep && mediaPlayer == null) { 61 | // The volume on STREAM_SYSTEM is not adjustable, and users found it 62 | // too loud, 63 | // so we now play on the music stream. 64 | activity.setVolumeControlStream(AudioManager.STREAM_MUSIC); 65 | mediaPlayer = buildMediaPlayer(activity); 66 | } 67 | } 68 | 69 | public synchronized void playBeepSoundAndVibrate() { 70 | if (playBeep && mediaPlayer != null) { 71 | mediaPlayer.start(); 72 | } 73 | if (vibrate) { 74 | Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); 75 | vibrator.vibrate(VIBRATE_DURATION); 76 | } 77 | } 78 | 79 | static boolean shouldBeep(SharedPreferences prefs, Context activity) { 80 | boolean shouldPlayBeep = true; 81 | if (shouldPlayBeep) { 82 | // See if sound settings overrides this 83 | AudioManager audioService = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); 84 | if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) { 85 | shouldPlayBeep = false; 86 | } 87 | } 88 | return shouldPlayBeep; 89 | } 90 | 91 | MediaPlayer buildMediaPlayer(Context activity) { 92 | MediaPlayer mediaPlayer = new MediaPlayer(); 93 | mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 94 | mediaPlayer.setOnCompletionListener(this); 95 | mediaPlayer.setOnErrorListener(this); 96 | try { 97 | AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep); 98 | try { 99 | mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength()); 100 | } finally { 101 | file.close(); 102 | } 103 | mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); 104 | mediaPlayer.prepare(); 105 | return mediaPlayer; 106 | } catch (IOException ioe) { 107 | Log.w(TAG, ioe); 108 | mediaPlayer.release(); 109 | return null; 110 | } 111 | } 112 | 113 | @Override 114 | public void onCompletion(MediaPlayer mp) { 115 | // When the beep has finished playing, rewind to queue up another one. 116 | mp.seekTo(0); 117 | } 118 | 119 | @Override 120 | public synchronized boolean onError(MediaPlayer mp, int what, int extra) { 121 | if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) { 122 | // we are finished, so put up an appropriate error toast if required 123 | // and finish 124 | activity.finish(); 125 | } else { 126 | // possibly media player error, so release and recreate 127 | mp.release(); 128 | mediaPlayer = null; 129 | updatePrefs(); 130 | } 131 | return true; 132 | } 133 | 134 | @Override 135 | public synchronized void close() { 136 | if (mediaPlayer != null) { 137 | mediaPlayer.release(); 138 | mediaPlayer = null; 139 | } 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/utils/BitmapUtil.java: -------------------------------------------------------------------------------- 1 | package com.liang.scancode.zxing.utils; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.BitmapFactory; 5 | import android.util.Log; 6 | 7 | /** 8 | * Created by 刘红亮 on 2015/7/23 22:30. 9 | */ 10 | public class BitmapUtil { 11 | 12 | 13 | /** 14 | * 15 | * @param options 16 | * @param reqWidth 17 | * @param reqHeight 18 | * @return 19 | */ 20 | public static int calculateInSampleSize(BitmapFactory.Options options, 21 | int reqWidth, int reqHeight) { 22 | // 源图片的高度和宽度 23 | final int height = options.outHeight; 24 | final int width = options.outWidth; 25 | //压缩当前图片占用内存不超过应用可用内存的3/4 26 | //ARGB_8888 一个像素占用4个字节 27 | //1兆字节(mb)=1048576字节(b) 28 | while(reqHeight*reqWidth*4> AppliationUtil.FREE_MEMORY*1048576/4*3){ 29 | reqHeight-=50; 30 | reqWidth-=50; 31 | } 32 | int inSampleSize = 1; 33 | if (height > reqHeight || width > reqWidth) { 34 | // 计算出实际宽高和目标宽高的比率 35 | final int heightRatio = Math.round((float) height / (float) reqHeight); 36 | final int widthRatio = Math.round((float) width / (float) reqWidth); 37 | // 选择宽和高中最小的比率作为inSampleSize的值,这样可以保证最终图片的宽和高 38 | // 一定都会大于等于目标的宽和高。 39 | inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; 40 | } 41 | if(inSampleSize==0) return 1; 42 | Log.e("hongliang","inSampleSize=" + inSampleSize); 43 | return inSampleSize; 44 | } 45 | public static Bitmap decodeBitmapFromPath(String photo_path, int reqWidth, int reqHeight) { 46 | // 第一次解析将inJustDecodeBounds设置为true,来获取图片大小 47 | final BitmapFactory.Options options = new BitmapFactory.Options(); 48 | options.inJustDecodeBounds = true; 49 | Bitmap scanBitmap = BitmapFactory.decodeFile(photo_path, options); 50 | // 调用上面定义的方法计算inSampleSize值 51 | options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 52 | // 使用获取到的inSampleSize值再次解析图片 53 | options.inJustDecodeBounds = false; 54 | return BitmapFactory.decodeFile(photo_path, options); 55 | } 56 | } -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/utils/CaptureActivityHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.liang.scancode.zxing.utils; 18 | 19 | import android.os.Bundle; 20 | import android.os.Handler; 21 | import android.os.Message; 22 | 23 | import com.google.zxing.Result; 24 | import com.liang.scancode.R; 25 | import com.liang.scancode.zxing.ScanManager; 26 | import com.liang.scancode.zxing.camera.CameraManager; 27 | import com.liang.scancode.zxing.decode.DecodeThread; 28 | 29 | /** 30 | * This class handles shouquan_ic_all the messaging which comprises the state machine for 31 | * capture. 32 | * 33 | * @author dswitkin@google.com (Daniel Switkin) 34 | */ 35 | public class CaptureActivityHandler extends Handler { 36 | 37 | final ScanManager scanManager; 38 | final DecodeThread decodeThread; 39 | final CameraManager cameraManager; 40 | State state; 41 | 42 | enum State { 43 | PREVIEW, SUCCESS, DONE 44 | } 45 | 46 | public CaptureActivityHandler(ScanManager scanManager, CameraManager cameraManager, int decodeMode) { 47 | this.scanManager = scanManager; 48 | decodeThread = new DecodeThread(scanManager, decodeMode); 49 | decodeThread.start(); 50 | state = State.SUCCESS; 51 | 52 | // Start ourselves capturing previews and decoding. 53 | this.cameraManager = cameraManager; 54 | cameraManager.startPreview(); 55 | restartPreviewAndDecode(); 56 | } 57 | 58 | @Override 59 | public void handleMessage(Message message) { 60 | switch (message.what) { 61 | case R.id.restart_preview: 62 | restartPreviewAndDecode(); 63 | break; 64 | case R.id.decode_succeeded: 65 | state = State.SUCCESS; 66 | Bundle bundle = message.getData(); 67 | 68 | scanManager.handleDecode((Result) message.obj, bundle); 69 | break; 70 | case R.id.decode_failed: 71 | // We're decoding as fast as possible, so when one decode fails, 72 | // start another. 73 | state = State.PREVIEW; 74 | cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode); 75 | break; 76 | case R.id.decode_error: 77 | scanManager.handleDecodeError((Exception)message.obj); 78 | break; 79 | case R.id.return_scan_result: 80 | // activity.setResult(Activity.RESULT_OK, (Intent) message.obj); 81 | // activity.finish(); 82 | break; 83 | } 84 | } 85 | 86 | public void quitSynchronously() { 87 | state = State.DONE; 88 | cameraManager.stopPreview(); 89 | Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit); 90 | quit.sendToTarget(); 91 | try { 92 | // Wait at most half a shouquan_icon_second; should be enough time, and onPause() 93 | // will timeout quickly 94 | decodeThread.join(500L); 95 | } catch (InterruptedException e) { 96 | // continue 97 | } 98 | 99 | // Be absolutely sure we don't send any queued up messages 100 | removeMessages(R.id.decode_succeeded); 101 | removeMessages(R.id.decode_failed); 102 | } 103 | 104 | void restartPreviewAndDecode() { 105 | if (state == State.SUCCESS) { 106 | state = State.PREVIEW; 107 | cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode); 108 | } 109 | } 110 | /** 111 | * 112 | * @return 返回当前扫描状态,是否可扫描,State.PREVIEW 是可扫描状态 113 | */ 114 | public boolean isScanning() { 115 | if(state == State.PREVIEW){ 116 | return true; 117 | } 118 | return false; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /app/src/main/java/com/liang/scancode/zxing/utils/InactivityTimer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.liang.scancode.zxing.utils; 18 | 19 | import android.annotation.SuppressLint; 20 | import android.app.Activity; 21 | import android.content.BroadcastReceiver; 22 | import android.content.Context; 23 | import android.content.Intent; 24 | import android.content.IntentFilter; 25 | import android.os.AsyncTask; 26 | import android.os.BatteryManager; 27 | import android.os.Build; 28 | import android.util.Log; 29 | 30 | /** 31 | * Finishes an activity after a period of inactivity if the device is on battery 32 | * power. 33 | */ 34 | public class InactivityTimer { 35 | 36 | static final String TAG = InactivityTimer.class.getSimpleName(); 37 | 38 | static final long INACTIVITY_DELAY_MS = 5 * 60 * 1000L; 39 | 40 | Activity activity; 41 | BroadcastReceiver powerStatusReceiver; 42 | boolean registered; 43 | AsyncTask inactivityTask; 44 | 45 | public InactivityTimer(Activity activity) { 46 | this.activity = activity; 47 | powerStatusReceiver = new PowerStatusReceiver(); 48 | registered = false; 49 | onActivity(); 50 | } 51 | 52 | @SuppressLint("NewApi") 53 | public synchronized void onActivity() { 54 | cancel(); 55 | inactivityTask = new InactivityAsyncTask(); 56 | if (Build.VERSION.SDK_INT >= 11) { 57 | inactivityTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 58 | } else { 59 | inactivityTask.execute(); 60 | } 61 | } 62 | 63 | public synchronized void onPause() { 64 | cancel(); 65 | if (registered) { 66 | activity.unregisterReceiver(powerStatusReceiver); 67 | registered = false; 68 | } else { 69 | Log.w(TAG, "PowerStatusReceiver was never registered?"); 70 | } 71 | } 72 | 73 | public synchronized void onResume() { 74 | if (registered) { 75 | Log.w(TAG, "PowerStatusReceiver was already registered?"); 76 | } else { 77 | activity.registerReceiver(powerStatusReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); 78 | registered = true; 79 | } 80 | onActivity(); 81 | } 82 | 83 | synchronized void cancel() { 84 | AsyncTask task = inactivityTask; 85 | if (task != null) { 86 | task.cancel(true); 87 | inactivityTask = null; 88 | } 89 | } 90 | 91 | public void shutdown() { 92 | cancel(); 93 | } 94 | 95 | class PowerStatusReceiver extends BroadcastReceiver { 96 | @Override 97 | public void onReceive(Context context, Intent intent) { 98 | if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) { 99 | // 0 indicates that we're on battery 100 | boolean onBatteryNow = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) <= 0; 101 | if (onBatteryNow) { 102 | InactivityTimer.this.onActivity(); 103 | } else { 104 | InactivityTimer.this.cancel(); 105 | } 106 | } 107 | } 108 | } 109 | 110 | class InactivityAsyncTask extends AsyncTask { 111 | @Override 112 | protected Object doInBackground(Object... objects) { 113 | try { 114 | Thread.sleep(INACTIVITY_DELAY_MS); 115 | Log.i(TAG, "Finishing activity due to inactivity"); 116 | activity.finish(); 117 | } catch (InterruptedException e) { 118 | // continue without killing 119 | } 120 | return null; 121 | } 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /app/src/main/res/anim/popupwin_nearperson_exit.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/anim/popupwin_nearperson_show.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/anim/shouquan_dialog_enter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/anim/shouquan_dialog_exit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-hdpi/arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/flashlight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-hdpi/flashlight.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_orderform_arrow_fanhui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-hdpi/ic_orderform_arrow_fanhui.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/kai.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-hdpi/kai.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/flashlight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/flashlight.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_my_returns_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/ic_my_returns_arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_orderform_arrow_fanhui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/ic_orderform_arrow_fanhui.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_seller_seeps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/ic_seller_seeps.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/kai.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/kai.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/scan2code_icon_back_nor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/scan2code_icon_back_nor.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/scan2code_icon_back_sel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/scan2code_icon_back_sel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/scan2code_icon_light_nor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/scan2code_icon_light_nor.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/scan2code_icon_light_sel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/scan2code_icon_light_sel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/scan2code_icon_xiangce.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/scan2code_icon_xiangce.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/scan2code_icon_xiangce_sel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/scan2code_icon_xiangce_sel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/scanning_line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/scanning_line.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/shouquan_icon_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/shouquan_icon_error.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/shouquan_icon_ok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/shouquan_icon_ok.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/shouquan_iloading_progress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/shouquan_iloading_progress.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/yundan_scanline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xhdpi/yundan_scanline.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xxhdpi/arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/flashlight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xxhdpi/flashlight.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_orderform_arrow_fanhui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xxhdpi/ic_orderform_arrow_fanhui.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_seller_seeps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xxhdpi/ic_seller_seeps.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/kai.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable-xxhdpi/kai.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/base_bgpic.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/head.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liang530/ScanCode/404dbb4ca7830eab5e07c37ec54b3e86999f33c4/app/src/main/res/drawable/head.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/rescan_shape_button.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shouquan_bg_loading_dialog_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shouquan_loading_dialog_progressbar.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shouquan_qrcode_g_gallery.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shouquan_qrcode_ic_back.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shouquan_qrcode_s_flashgun.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_create_code.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 17 | 22 |