commit 387082cba872cb89195657690d95ec9a2c6b9781 Author: Jenly Date: Thu Aug 9 16:17:49 2018 +0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5edb4ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.iml +.gradle +/local.properties +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml new file mode 100644 index 0000000..45853aa --- /dev/null +++ b/.idea/assetWizardSettings.xml @@ -0,0 +1,57 @@ + + + + + + \ No newline at end of file diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser new file mode 100644 index 0000000..2279136 Binary files /dev/null and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..5d6f65c --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml new file mode 100644 index 0000000..2d579f3 --- /dev/null +++ b/.idea/markdown-navigator.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml new file mode 100644 index 0000000..57927c5 --- /dev/null +++ b/.idea/markdown-navigator/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..99202cc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..35b743c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,28 @@ +language: android +jdk: oraclejdk8 +before_install: +- yes | sdkmanager "platforms;android-27" + +env: + global: + - ANDROID_API_LEVEL=27 + - ANDROID_BUILD_TOOLS_VERSION=27.0.3 + - TRAVIS_SECURE_ENV_VARS=true + +android: + components: + # The BuildTools version used by your project + - tools + - platform-tools + - build-tools-$ANDROID_BUILD_TOOLS_VERSION + - extra-android-m2repository + - extra-google-android-support + + # The SDK version used to compile your project + - android-$ANDROID_API_LEVEL + licenses: + - '.+' + +script: + - ./gradlew clean + - ./gradlew assembleDebug \ No newline at end of file diff --git a/GIF.gif b/GIF.gif new file mode 100644 index 0000000..2d954b5 Binary files /dev/null and b/GIF.gif differ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8dada3e --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5a06c5c --- /dev/null +++ b/README.md @@ -0,0 +1,112 @@ +# ZXingLite + +![Image](app/src/main/ic_launcher-web.png) + +[![Download](https://img.shields.io/badge/download-App-blue.svg)](https://raw.githubusercontent.com/jenly1314/ZXingLite/master/app/release/app-release.apk) +[![](https://jitpack.io/v/jenly1314/ZXingLite.svg)](https://jitpack.io/#jenly1314/ZXingLite) +[![CI](https://travis-ci.org/jenly1314/ZXingLite.svg?branch=master)](https://travis-ci.org/jenly1314/ZXingLite) +[![API](https://img.shields.io/badge/API-15%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=15) +[![License](https://img.shields.io/badge/license-Apche%202.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0) +[![Blog](https://img.shields.io/badge/blog-Jenly-9933CC.svg)](http://blog.csdn.net/jenly121) + +ZXingLite for Android 是ZXing的精简版,优化扫码和生成二维码功能,扫码界面支持完全自定义,让集成更简单。 + +## Gif 展示 +![Image](GIF.gif) + + +## ViewfinderView属性说明 +| 属性 | 值类型 | 默认值 | 说明 | +| :------| :------ | :------ | :------ | +| maskColor | color |#60000000| 扫描区外遮罩的颜色 | +| frameColor | color |#7F1FB3E2| 扫描区边框的颜色 | +| cornerColor | color |#FF1FB3E2| 扫描区边角的颜色 | +| laserColor | color |#FF1FB3E2| 扫描区激光线的颜色 | +| resultPointColor | color |#C0EFBD21| 扫描区结果点的颜色 | +| text | string || 扫描提示文本信息 | +| textColor | color |#FFC0C0C0| 提示文本字体颜色 | +| textSize | dimension |14sp| 提示文本字体大小 | +| textPadding | dimension |24dp| 提示文本距离扫描区的间距 | +| textLocation | enum |top| 提示文本信息显示的位置 | + +## 引入 + +### Maven: +```maven + + com.king.zxing + zxing-lite + 1.0.0 + pom + +``` +### Gradle: +```gradle +implementation 'com.king.zxing:zxing-lite:1.0.0' +``` +### Lvy: +```lvy + + + +``` + +###### 如果Gradle出现compile失败的情况,可以在Project的build.gradle里面添加如下:(也可以使用上面的GitPack来complie) +```gradle +allprojects { + repositories { + maven { url 'https://dl.bintray.com/jenly/maven' } + } +} +``` + +## 引入的库: +```gradle +compileOnly 'com.android.support:appcompat-v7:27.1.1' +api 'com.com.google.zxing:core:3.3.3' +``` + +## 示例 + +布局示例 (可自定义布局,布局内至少要保证有SurfaceView和ViewfinderView,控件id可根据重写CaptureActivity 的 getPreviewViewId 和 getViewFinderViewId方法自定义) +```Xml + + + + +``` + +代码示例 (二维码/条形码) +```Java + //生成二维码 + CodeUtils.createQRCode(content,600,logo); + //生成条形码 + CodeUtils.createBarCode(content, BarcodeFormat.CODE_128,800,200); +``` + +更多使用详情,请查看[app](app)中的源码使用示例 + +## 关于我 + Name: Jenly + + Email: jenly1314#gmail.com / jenly1314#vip.qq.com + + CSDN: jenly121 + + Github: jenly1314 + + 微信公众号: + + ![公众号](http://olambmg9j.bkt.clouddn.com/jenly666.jpg) + + 加入QQ群: 20867961 + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..8e18729 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,36 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion build_versions.compileSdk + buildToolsVersion build_versions.buildTools + defaultConfig { + applicationId "com.king.zxing.app" + minSdkVersion build_versions.minSdk + targetSdkVersion build_versions.targetSdk + versionCode app_version.versionCode + versionName app_version.versionName + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + testImplementation deps.test.junit + androidTestImplementation deps.test.runner + androidTestImplementation deps.test.espresso + //support + implementation deps.support.design + implementation deps.support.appcompat + implementation deps.support.constraintlayout + + implementation deps.easypermissions + + implementation project(':lib') +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/release/app-release.apk b/app/release/app-release.apk new file mode 100644 index 0000000..f33d59b Binary files /dev/null and b/app/release/app-release.apk differ diff --git a/app/release/output.json b/app/release/output.json new file mode 100644 index 0000000..a7b1e07 --- /dev/null +++ b/app/release/output.json @@ -0,0 +1 @@ +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file diff --git a/app/src/androidTest/java/com/king/zxing/app/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/king/zxing/app/ExampleInstrumentedTest.java new file mode 100644 index 0000000..7ac649e --- /dev/null +++ b/app/src/androidTest/java/com/king/zxing/app/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.king.zxing.app; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.king.zxing.app", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..b66ddcf --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png new file mode 100644 index 0000000..36fd871 Binary files /dev/null and b/app/src/main/ic_launcher-web.png differ diff --git a/app/src/main/java/com/king/zxing/app/CodeActivity.java b/app/src/main/java/com/king/zxing/app/CodeActivity.java new file mode 100644 index 0000000..6f602e6 --- /dev/null +++ b/app/src/main/java/com/king/zxing/app/CodeActivity.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2018 Jenly Yu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.king.zxing.app; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import com.google.zxing.BarcodeFormat; +import com.king.zxing.util.CodeUtils; + +/** + * @author Jenly Jenly + */ +public class CodeActivity extends AppCompatActivity { + + private TextView tvTitle; + private ImageView ivCode; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.code_activity); + ivCode = findViewById(R.id.ivCode); + tvTitle = findViewById(R.id.tvTitle); + tvTitle.setText(getIntent().getStringExtra(MainActivity.KEY_TITLE)); + boolean isQRCode = getIntent().getBooleanExtra(MainActivity.KEY_IS_QR_CODE,false); + + if(isQRCode){ + createQRCode(getString(R.string.app_name)); + }else{ + createBarCode(getString(R.string.app_name)); + } + } + + /** + * 生成二维码 + * @param content + */ + private void createQRCode(String content){ + //生成二维码最好放子线程生成防止阻塞UI,这里只是演示 + Bitmap logo = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher); + Bitmap bitmap = CodeUtils.createQRCode(content,600,logo); + //显示二维码 + ivCode.setImageBitmap(bitmap); + } + + /** + * 生成条形码 + * @param content + */ + private void createBarCode(String content){ + //生成条形码最好放子线程生成防止阻塞UI,这里只是演示 + Bitmap bitmap = CodeUtils.createBarCode(content, BarcodeFormat.CODE_128,800,200); + //显示条形码 + ivCode.setImageBitmap(bitmap); + } + + + public void OnClick(View v){ + switch (v.getId()){ + case R.id.ivLeft: + onBackPressed(); + break; + } + } +} diff --git a/app/src/main/java/com/king/zxing/app/CustomCaptureActivity.java b/app/src/main/java/com/king/zxing/app/CustomCaptureActivity.java new file mode 100644 index 0000000..a8a88d8 --- /dev/null +++ b/app/src/main/java/com/king/zxing/app/CustomCaptureActivity.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2018 Jenly Yu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.king.zxing.app; + +import android.hardware.Camera; +import android.os.Bundle; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.widget.TextView; + +import com.king.zxing.CaptureActivity; +import com.king.zxing.app.util.StatusBarUtils; + +/** + * @author Jenly Jenly + */ +public class CustomCaptureActivity extends CaptureActivity { + + @Override + public int getLayoutId() { + return R.layout.custom_capture_activity; + } + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + Toolbar toolbar = findViewById(R.id.toolbar); + StatusBarUtils.immersiveStatusBar(this,toolbar,0.2f); + TextView tvTitle = findViewById(R.id.tvTitle); + tvTitle.setText(getIntent().getStringExtra(MainActivity.KEY_TITLE)); + + getBeepManager().setPlayBeep(true); + getBeepManager().setVibrate(true); + } + + private void offFlash(){ + Camera camera = getCameraManager().getOpenCamera().getCamera(); + Camera.Parameters parameters = camera.getParameters(); + parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); + camera.setParameters(parameters); + } + + public void openFlash(){ + Camera camera = getCameraManager().getOpenCamera().getCamera(); + Camera.Parameters parameters = camera.getParameters(); + parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); + camera.setParameters(parameters); + } + + + private void clickFlash(View v){ + if(v.isSelected()){ + offFlash(); + v.setSelected(false); + }else{ + openFlash(); + v.setSelected(true); + } + + } + + public void OnClick(View v){ + switch (v.getId()){ + case R.id.ivLeft: + onBackPressed(); + break; + case R.id.ivFlash: + clickFlash(v); + break; + } + } +} diff --git a/app/src/main/java/com/king/zxing/app/EasyCaptureActivity.java b/app/src/main/java/com/king/zxing/app/EasyCaptureActivity.java new file mode 100644 index 0000000..ca4882f --- /dev/null +++ b/app/src/main/java/com/king/zxing/app/EasyCaptureActivity.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2018 Jenly Yu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.king.zxing.app; + +import android.os.Bundle; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.widget.TextView; + +import com.king.zxing.CaptureActivity; +import com.king.zxing.app.util.StatusBarUtils; + +/** + * @author Jenly Jenly + */ +public class EasyCaptureActivity extends CaptureActivity { + + + @Override + public int getLayoutId() { + return R.layout.easy_capture_activity; + } + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + Toolbar toolbar = findViewById(R.id.toolbar); + StatusBarUtils.immersiveStatusBar(this,toolbar,0.2f); + TextView tvTitle = findViewById(R.id.tvTitle); + tvTitle.setText(getIntent().getStringExtra(MainActivity.KEY_TITLE)); + + } + + public void OnClick(View v){ + switch (v.getId()){ + case R.id.ivLeft: + onBackPressed(); + break; + } + } +} diff --git a/app/src/main/java/com/king/zxing/app/MainActivity.java b/app/src/main/java/com/king/zxing/app/MainActivity.java new file mode 100644 index 0000000..b25ddd4 --- /dev/null +++ b/app/src/main/java/com/king/zxing/app/MainActivity.java @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2018 Jenly Yu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.king.zxing.app; + +import android.Manifest; +import android.content.Intent; +import android.support.v4.app.ActivityCompat; +import android.support.v4.app.ActivityOptionsCompat; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.Toast; +import com.king.zxing.CaptureActivity; +import com.king.zxing.Intents; + +import java.util.List; + +import pub.devrel.easypermissions.AfterPermissionGranted; +import pub.devrel.easypermissions.EasyPermissions; + +public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks{ + + public static final String KEY_TITLE = "key_title"; + public static final String KEY_IS_QR_CODE = "key_code"; + + public static final int REQUEST_CODE = 0X01; + + public static final int RC_CAMERA = 0X01; + + private Class cls; + private String title; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if(resultCode == RESULT_OK){ + if(data!=null){ + //识别结果 + String result = data.getStringExtra(Intents.Scan.RESULT); + Toast.makeText(this,result,Toast.LENGTH_SHORT).show(); + } + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + + // Forward results to EasyPermissions + EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); + } + + @Override + public void onPermissionsGranted(int requestCode, List list) { + // Some permissions have been granted + startScan(cls,title); + } + + @Override + public void onPermissionsDenied(int requestCode, List list) { + // Some permissions have been denied + // ... + } + + /** + * 检测拍摄权限 + * @param cls + * @param title + */ + @AfterPermissionGranted(RC_CAMERA) + private void checkCameraPermissions(Class cls,String title){ + this.cls = cls; + this.title = title; + String[] perms = {Manifest.permission.CAMERA}; + if (EasyPermissions.hasPermissions(this, perms)) {//有权限 + startScan(cls,title); + } else { + // Do not have permissions, request them now + EasyPermissions.requestPermissions(this, getString(R.string.permission_camera), + RC_CAMERA, perms); + } + } + + /** + * 扫码 + * @param cls + * @param title + */ + private void startScan(Class cls,String title){ + ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeCustomAnimation(this,R.anim.in,R.anim.out); + Intent intent = new Intent(this, cls); + intent.putExtra(KEY_TITLE,title); + ActivityCompat.startActivityForResult(this,intent,REQUEST_CODE,optionsCompat.toBundle()); + } + + /** + * 生成二维码/条形码 + * @param isQRCode + */ + private void startCode(boolean isQRCode){ + Intent intent = new Intent(this,CodeActivity.class); + intent.putExtra(KEY_IS_QR_CODE,isQRCode); + intent.putExtra(KEY_TITLE,isQRCode ? getString(R.string.qr_code) : getString(R.string.bar_code)); + startActivity(intent); + } + + public void OnClick(View v){ + switch (v.getId()){ + case R.id.btn1: + checkCameraPermissions(CaptureActivity.class, ((Button)v).getText().toString()); + break; + case R.id.btn2: + checkCameraPermissions(EasyCaptureActivity.class,((Button)v).getText().toString()); + break; + case R.id.btn3: + checkCameraPermissions(CustomCaptureActivity.class,((Button)v).getText().toString()); + break; + case R.id.btn4: + startCode(false); + break; + case R.id.btn5: + startCode(true); + break; + } + + } +} diff --git a/app/src/main/java/com/king/zxing/app/util/StatusBarUtils.java b/app/src/main/java/com/king/zxing/app/util/StatusBarUtils.java new file mode 100644 index 0000000..95cdf00 --- /dev/null +++ b/app/src/main/java/com/king/zxing/app/util/StatusBarUtils.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2018 Jenly Yu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.king.zxing.app.util; + +import android.app.Activity; +import android.content.Context; +import android.graphics.Color; +import android.os.Build; +import android.support.annotation.ColorInt; +import android.support.annotation.FloatRange; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; +import android.widget.LinearLayout; + +import com.king.zxing.app.R; + +/** + * @author Jenly Jenly + */ +public enum StatusBarUtils { + INSTANCE; + + public static void immersiveStatusBar(Activity activity,Toolbar toolbar) { + immersiveStatusBar(activity,toolbar,0.0f); + } + + public static void immersiveStatusBar(Activity activity,Toolbar toolbar,@FloatRange(from = 0.0, to = 1.0) float alpha) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { + return; + } + + Window window = activity.getWindow(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.setStatusBarColor(Color.TRANSPARENT); + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + } else { + window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + } + + ViewGroup decorView = (ViewGroup) window.getDecorView(); + ViewGroup contentView = window.getDecorView().findViewById(Window.ID_ANDROID_CONTENT); + View rootView = contentView.getChildAt(0); + if (rootView != null) { + rootView.setFitsSystemWindows(false); + } + if(toolbar!=null){ + toolbar.setPadding(0,getStatusBarHeight(activity),0,0); + } + + decorView.addView(createStatusBarView(activity,alpha)); + } + + private static View createStatusBarView(Activity activity,@FloatRange(from = 0.0, to = 1.0) float alpha) { + // 绘制一个和状态栏一样高的矩形 + View statusBarView = new View(activity); + LinearLayout.LayoutParams params = + new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity)); + statusBarView.setLayoutParams(params); + statusBarView.setBackgroundColor(Color.argb((int) (alpha * 255), 0, 0, 0)); + statusBarView.setId(R.id.translucent_view); + return statusBarView; + } + + /** 获取状态栏高度 */ + public static int getStatusBarHeight(Context context) { + return context.getResources().getDimensionPixelSize(R.dimen.status_bar_height); + } +} diff --git a/app/src/main/res/anim/in.xml b/app/src/main/res/anim/in.xml new file mode 100644 index 0000000..f0bf599 --- /dev/null +++ b/app/src/main/res/anim/in.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/app/src/main/res/anim/out.xml b/app/src/main/res/anim/out.xml new file mode 100644 index 0000000..9e8b099 --- /dev/null +++ b/app/src/main/res/anim/out.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c3903ed --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable-xxhdpi/btn_back_normal.png b/app/src/main/res/drawable-xxhdpi/btn_back_normal.png new file mode 100644 index 0000000..9c6de1b Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/btn_back_normal.png differ diff --git a/app/src/main/res/drawable-xxhdpi/btn_back_pressed.png b/app/src/main/res/drawable-xxhdpi/btn_back_pressed.png new file mode 100644 index 0000000..af1c2f4 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/btn_back_pressed.png differ diff --git a/app/src/main/res/drawable-xxhdpi/btn_none.png b/app/src/main/res/drawable-xxhdpi/btn_none.png new file mode 100644 index 0000000..75907be Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/btn_none.png differ diff --git a/app/src/main/res/drawable-xxhdpi/flash_off.png b/app/src/main/res/drawable-xxhdpi/flash_off.png new file mode 100644 index 0000000..6f351bf Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/flash_off.png differ diff --git a/app/src/main/res/drawable-xxhdpi/flash_on.png b/app/src/main/res/drawable-xxhdpi/flash_on.png new file mode 100644 index 0000000..8213c66 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/flash_on.png differ diff --git a/app/src/main/res/drawable/btn_back_selector.xml b/app/src/main/res/drawable/btn_back_selector.xml new file mode 100644 index 0000000..196d472 --- /dev/null +++ b/app/src/main/res/drawable/btn_back_selector.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/flash_selected_selector.xml b/app/src/main/res/drawable/flash_selected_selector.xml new file mode 100644 index 0000000..b20586c --- /dev/null +++ b/app/src/main/res/drawable/flash_selected_selector.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..5713f34 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..e68755a --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,101 @@ + + + + + + +