Compare commits
180 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d09b7c76c3 | |||
| 3a2db7ffc6 | |||
| 2a65a6c973 | |||
| 3c77f1d6c8 | |||
| b6c6421dd5 | |||
| 8173d4a8b2 | |||
| 8fdbbbef5e | |||
| 2324a5403e | |||
| c752130405 | |||
| 1c27c8fe2d | |||
| aa129af542 | |||
| 90b5db5fcd | |||
| 24d02945fe | |||
| 6ccf3a9d1a | |||
| 23f29e5a56 | |||
| 1a8d949325 | |||
| f1554b7478 | |||
| cc12c103e0 | |||
| a13ce2b161 | |||
| 0c97cf70cc | |||
| 9beeac7960 | |||
| cc34502f13 | |||
| 2221621de9 | |||
| 4d4c5a2c4e | |||
| 65d2716c71 | |||
| 7fd1ab8794 | |||
| 630e3cc0f8 | |||
| 40260272fc | |||
| f54615e43a | |||
| 1acc3a6f4f | |||
| 73093b9b4f | |||
| db85816b3d | |||
| 6a3d857019 | |||
| 6c8ea7e3fd | |||
| 35ee545f8b | |||
| 5d9e2c3756 | |||
| cce2a300ef | |||
| 13440ad875 | |||
| 5a2470f034 | |||
| 545672bb8f | |||
| 542dc66090 | |||
| ea414a236e | |||
| 1ba1ded540 | |||
| 4893bcc194 | |||
| 6498fad6a7 | |||
| f7f779d7ac | |||
| c555ffbe05 | |||
| e0d340952d | |||
| 9b924e6875 | |||
| 8df0cb554a | |||
| 09d992ddfa | |||
| 95cd4a3a4d | |||
| 7e5bbd2997 | |||
| 8d8cd7d445 | |||
| bd857c68eb | |||
| 0fdfbce9fb | |||
| eba457ee9e | |||
| 9319110de8 | |||
| ee4b181f23 | |||
| a4f751500c | |||
| 75b4aa57f5 | |||
| eb4cbd5095 | |||
| aa4fca5dae | |||
| d22b581cd3 | |||
| 9349b31ab3 | |||
| c0c8363f85 | |||
| 27c22e8ffe | |||
| d77fa29226 | |||
| 9aa5381c2b | |||
| 3a7612661a | |||
| 70f4bbb8de | |||
| 363ad77540 | |||
| 62547c10d7 | |||
| 0de49aa7c8 | |||
| 1a1c8d0e66 | |||
| 31332404fc | |||
| 28c646b9e2 | |||
| c0c0fcd745 | |||
| 98d00abcbd | |||
| 7042d74f4a | |||
| 94ae63d857 | |||
| 0e7413e1f7 | |||
| 82e8f9afcc | |||
| 6556f81558 | |||
| 5983e2fb8e | |||
| be04a7587f | |||
| 330cb2b63b | |||
| 6b49e8774f | |||
| 209e1c9a04 | |||
| c7a143499e | |||
| a4dfc2fca4 | |||
| 98b69af339 | |||
| 40010a62df | |||
| 5927f38a1d | |||
| f2a477b647 | |||
| 65aaa93a27 | |||
| 1e1b075f13 | |||
| 224bfd6ea2 | |||
| c1a3786c17 | |||
| 2af07f95cf | |||
| 4e7ee70b73 | |||
| aec45c4f10 | |||
| c1918b32fb | |||
| a2774c7bde | |||
| 2f061a1da5 | |||
| 70f4159e3a | |||
| 295193d613 | |||
| d8f3157e97 | |||
| a7d91dbed6 | |||
| e8257760da | |||
| 2f022c0a70 | |||
| 3fd9354cd7 | |||
| c98a04a407 | |||
| 8e90d15117 | |||
| fa2cd1562d | |||
| 11073ddcf9 | |||
| 17ad61674e | |||
| 8a67d852e4 | |||
| 68f17bde30 | |||
| 34788e0fbc | |||
| 45756b51b2 | |||
| adee48a8ae | |||
| e48229ac3f | |||
| 2ff44f91b5 | |||
| f30ea0c955 | |||
| cf4c0dce50 | |||
| 670000698d | |||
| 60ed28ee06 | |||
| c83b2c5a5c | |||
| eaeddd23af | |||
| 0fd028b9e2 | |||
| e2892cad8f | |||
| 1817bb198b | |||
| 29848b2b4f | |||
| 9ec92a5101 | |||
| 2cf4b60f0f | |||
| e3aed41746 | |||
| 09571d3813 | |||
| 6c250faeb6 | |||
| 4955c18a87 | |||
| 6f73f470c9 | |||
| 5d48d2ff35 | |||
| 92f6acf3d6 | |||
| 5309388c7a | |||
| b3a2c1e07e | |||
| 958bbb1491 | |||
| 34aca80673 | |||
| 0b774fba7c | |||
| 81effea784 | |||
| b4a88bfb56 | |||
| 6c3e917b15 | |||
| f484d21af8 | |||
| d3330c9663 | |||
| 964dbab7b2 | |||
| 76861f8683 | |||
| 42d09b810b | |||
| c4cbaba495 | |||
| 2373c88ca9 | |||
| 4f311133ee | |||
| 531918d28a | |||
| e3d3950d9a | |||
| 1b8fbe60cc | |||
| a2cc8e2756 | |||
| a7c8046c22 | |||
| 8992dc5710 | |||
| 33b88ed645 | |||
| 50e3acce09 | |||
| a8305bd237 | |||
| 11de8f4288 | |||
| c9e3bf415f | |||
| e27bef5518 | |||
| 9ea3e3ef08 | |||
| 03ab7214f6 | |||
| 0b07174be9 | |||
| 50ea6bb48a | |||
| aefdceaffd | |||
| 91157bc907 | |||
| 4c745d697b | |||
| 2219087d6a | |||
| c81ea8e6eb |
@@ -0,0 +1,21 @@
|
||||
name: Build Android
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
- name: Build and Lint with Gradle
|
||||
run: ./gradlew build
|
||||
- name: Archive lint results
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: lint-results
|
||||
path: "**/build/reports/lint-results*"
|
||||
@@ -8,3 +8,6 @@ maven-repository
|
||||
local.properties
|
||||
mvn-clone
|
||||
*.keystore
|
||||
.project
|
||||
.settings
|
||||
.classpath
|
||||
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
language: android
|
||||
jdk: oraclejdk7
|
||||
android:
|
||||
components:
|
||||
- extra-android-support
|
||||
- extra-android-m2repository
|
||||
- extra-google-m2repository
|
||||
# We need "tools" for build-tools. See https://github.com/travis-ci/travis-ci/issues/5036
|
||||
- tools
|
||||
- build-tools-23.0.2
|
||||
licenses:
|
||||
- 'android-sdk-license-.+'
|
||||
- 'google-gdk-license-.+'
|
||||
script:
|
||||
# build includes lint and test
|
||||
- TERM=dumb ./gradlew build
|
||||
|
||||
+69
@@ -1,3 +1,72 @@
|
||||
### 4.3.0 (2021-10-25)
|
||||
|
||||
* Minimum SDK version 19, but requires additional config (see readme) for < 24 compatibility.
|
||||
* Add ScanOptions and ScanContract for use with `registerForActivityResult()`.
|
||||
* Deprecates IntentIntegrator.
|
||||
* Use minimal AndroidX libraries.
|
||||
|
||||
### 4.2.0 (2021-03-15)
|
||||
|
||||
* Fix MediaPlayer warnings (#587).
|
||||
* Prevent CameraConfigurationUtils clash (#609).
|
||||
* Add licenses to POM (#556).
|
||||
* Bug: Crashes on SDK versions older than 21 (#645).
|
||||
|
||||
### 4.1.0 (2020-01-07)
|
||||
|
||||
* Ability to hide the laser in ViewfinderView (#503).
|
||||
* Make possibleResultPoints method in BarcodeCallback optional (#504).
|
||||
* Ability to customize or disable the permission error dialog (#505).
|
||||
|
||||
### 4.0.2 (2019-09-07)
|
||||
|
||||
* Use androidx.
|
||||
* Use zxing:core 3.4.0 by default.
|
||||
* Minimum SDK version 24.
|
||||
* Fix ArithmeticException.
|
||||
* Fix ResultPoint locations when camera is mirrored.
|
||||
|
||||
### 4.0.0 / 4.0.1 (2019-09-07)
|
||||
|
||||
* Broken release - use 4.0.2.
|
||||
|
||||
### 3.6.0 (2018-03-04)
|
||||
|
||||
* Use zxing:core 3.3.2 by default (#360).
|
||||
* Minimum SDK version 19, or 14 by using zxing:core 3.3.0.
|
||||
* Fix preview race condition (#324).
|
||||
* Request code can now specified per Intent, instead of globally (#287).
|
||||
* More helpers to specify barcode formats.
|
||||
* Allow scanning both inverted and non-inverted barcodes at the same time (alternating) (#326).
|
||||
* More examples.
|
||||
|
||||
### 3.5.0 (2017-03-20)
|
||||
|
||||
* Allow changing the REQUEST_CODE value (#234).
|
||||
* Add support for inverted scans (#235).
|
||||
* Use zxing:core 3.3.0 by default (#265).
|
||||
|
||||
Fixes:
|
||||
|
||||
* Fix memory leak when using scan timeout (#283).
|
||||
* Better handling of various camera errors (#241, #268, #270)
|
||||
|
||||
### 3.4.0 (2016-10-16)
|
||||
|
||||
Changes:
|
||||
|
||||
* Beep on scan is now controlled only by the media volume, and still plays
|
||||
even if the device is in "silent mode", as long as the media volume is not muted.
|
||||
* The 150ms delay after scanning is removed.
|
||||
|
||||
Fixes:
|
||||
|
||||
* An issue where the beep sometimes played twice is fixed (#221).
|
||||
* Fix rare crash (#209)
|
||||
* Fix orientation lock issue (#181)
|
||||
* Fix race condition with TextureView (#204)
|
||||
|
||||
|
||||
### 3.3.0 (2016-06-05)
|
||||
|
||||
* Add an optional timeout to cancel scanning. (#161)
|
||||
|
||||
@@ -10,11 +10,26 @@ For more control over the UI or scanning behaviour, some components may be used
|
||||
|
||||
These components can be used from any Activity or Fragment.
|
||||
|
||||
This is much more low-level than using IntentIntegrator. Your code becomes responsible for:
|
||||
* Setting up the BarcodeView (doesn't have all the helpers from IntentIntegrator)*
|
||||
* Requesting permission to do the Camera.
|
||||
* Making sure only one Camera instance is active at a time.
|
||||
* Handling the scan results.
|
||||
|
||||
Samples:
|
||||
* [ContinuousCaptureActivity][6]: continuously scan and display results (instead of a once-off scan).
|
||||
* [ToolbarCaptureActivity][8]: Same as the normal CaptureActivity, but with a Lollipop Toolbar.
|
||||
|
||||
|
||||
## Notes on threading
|
||||
|
||||
For a responsive user interface, all camera operations happen on a dedicated background thread.
|
||||
In most cases this doesn't matter, but it does mean that the camera is not released immediately
|
||||
when the BarcodeView is paused. If you want to start using the camera for something else
|
||||
immediately after scanning, use `BarcodeView#pauseAndWait()` instead of `BarcodeView#pause()`.
|
||||
This will block the main thread until the camera is released.
|
||||
|
||||
|
||||
## Notes on scaling
|
||||
|
||||
On each Android device, the camera has a set list of available preview sizes. When embedding the
|
||||
|
||||
@@ -13,72 +13,172 @@ Features:
|
||||
|
||||
A sample application is available in [Releases](https://github.com/journeyapps/zxing-android-embedded/releases).
|
||||
|
||||
By default, Android SDK 24+ is required because of `zxing:core` 3.4.x.
|
||||
SDK 19+ is supported with additional configuration, see [Older SDK versions](#older-sdk-versions).
|
||||
|
||||
## Adding aar dependency with Gradle
|
||||
|
||||
From version 3 this is a single library, supporting Gingerbread and later versions of Android
|
||||
(API level 9+). If you need support for earlier Android versions, use [version 2][4].
|
||||
|
||||
Add the following to your build.gradle file:
|
||||
Add the following to your `build.gradle` file:
|
||||
|
||||
```groovy
|
||||
// Config for SDK 24+
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.journeyapps:zxing-android-embedded:3.3.0@aar'
|
||||
compile 'com.google.zxing:core:3.2.1'
|
||||
compile 'com.android.support:appcompat-v7:23.1.0' // Version 23+ is required
|
||||
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
|
||||
}
|
||||
|
||||
android {
|
||||
buildToolsVersion '23.0.2' // Older versions may give compile errors
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Usage with IntentIntegrator
|
||||
## Older SDK versions
|
||||
|
||||
Launch the intent with the default options:
|
||||
```java
|
||||
new IntentIntegrator(this).initiateScan(); // `this` is the current Activity
|
||||
By default, only SDK 24+ will work, even though the library specifies 19 as the minimum version.
|
||||
|
||||
For SDK versions 19+, one of the changes below are required.
|
||||
Some older SDK versions below 19 may work, but this is not tested or supported.
|
||||
|
||||
// Get the results:
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
||||
if(result != null) {
|
||||
if(result.getContents() == null) {
|
||||
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
### Option 1. Downgrade zxing:core to 3.3.0
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation('com.journeyapps:zxing-android-embedded:4.3.0') { transitive = false }
|
||||
implementation 'com.google.zxing:core:3.3.0'
|
||||
}
|
||||
```
|
||||
|
||||
### Option 2: Desugaring (Advanced)
|
||||
|
||||
This option does not require changing library versions, but may complicate the build process.
|
||||
|
||||
This requires Android Gradle Plugin version 4.0.0 or later.
|
||||
|
||||
See [Java 8+ API desugaring support](https://developer.android.com/studio/write/java8-support#library-desugaring).
|
||||
|
||||
Example for SDK 21+:
|
||||
|
||||
```groovy
|
||||
android {
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
// Flag to enable support for the new language APIs
|
||||
coreLibraryDesugaringEnabled true
|
||||
// Sets Java compatibility to Java 8
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
|
||||
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
|
||||
}
|
||||
```
|
||||
|
||||
Use from a Fragment:
|
||||
```java
|
||||
IntentIntegrator.forFragment(this).initiateScan(); // `this` is the current Fragment
|
||||
SDK 19+ additionally requires multiDex. In addition to these gradle config changes, the Application
|
||||
class must also be changed. See for details: [Configure your app for multidex](https://developer.android.com/studio/build/multidex#mdex-gradle).
|
||||
|
||||
// If you're using the support library, use IntentIntegrator.forSupportFragment(this) instead.
|
||||
```groovy
|
||||
android {
|
||||
defaultConfig {
|
||||
multiDexEnabled true
|
||||
minSdkVersion 19
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
// Flag to enable support for the new language APIs
|
||||
coreLibraryDesugaringEnabled true
|
||||
// Sets Java compatibility to Java 8
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
|
||||
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
|
||||
implementation "androidx.multidex:multidex:2.0.1"
|
||||
}
|
||||
```
|
||||
|
||||
## Hardware Acceleration
|
||||
|
||||
Hardware acceleration is required since TextureView is used.
|
||||
|
||||
Make sure it is enabled in your manifest file:
|
||||
|
||||
```xml
|
||||
<application android:hardwareAccelerated="true" ... >
|
||||
```
|
||||
|
||||
## Usage with ScanContract
|
||||
|
||||
Note: `startActivityForResult` is deprecated, so this example uses `registerForActivityResult` instead.
|
||||
See for details: https://developer.android.com/training/basics/intents/result
|
||||
|
||||
`startActivityForResult` can still be used via `IntentIntegrator`, but that is not recommended anymore.
|
||||
|
||||
```java
|
||||
// Register the launcher and result handler
|
||||
private final ActivityResultLauncher<ScanOptions> barcodeLauncher = registerForActivityResult(new ScanContract(),
|
||||
result -> {
|
||||
if(result.getContents() == null) {
|
||||
Toast.makeText(MyActivity.this, "Cancelled", Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(MyActivity.this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
// Launch
|
||||
public void onButtonClick(View view) {
|
||||
barcodeLauncher.launch(new ScanOptions());
|
||||
}
|
||||
```
|
||||
|
||||
Customize options:
|
||||
```java
|
||||
IntentIntegrator integrator = new IntentIntegrator(this);
|
||||
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
|
||||
integrator.setPrompt("Scan a barcode");
|
||||
integrator.setCameraId(0); // Use a specific camera of the device
|
||||
integrator.setBeepEnabled(false);
|
||||
integrator.setBarcodeImageEnabled(true);
|
||||
integrator.initiateScan();
|
||||
ScanOptions options = new ScanOptions();
|
||||
options.setDesiredBarcodeFormats(ScanOptions.ONE_D_CODE_TYPES);
|
||||
options.setPrompt("Scan a barcode");
|
||||
options.setCameraId(0); // Use a specific camera of the device
|
||||
options.setBeepEnabled(false);
|
||||
options.setBarcodeImageEnabled(true);
|
||||
barcodeLauncher.launch(options);
|
||||
```
|
||||
|
||||
See [IntentIntegrator][5] for more options.
|
||||
See [BarcodeOptions][5] for more options.
|
||||
|
||||
### Generate Barcode example
|
||||
|
||||
While this is not the primary purpose of this library, it does include basic support for
|
||||
generating some barcode types:
|
||||
|
||||
```java
|
||||
try {
|
||||
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
|
||||
Bitmap bitmap = barcodeEncoder.encodeBitmap("content", BarcodeFormat.QR_CODE, 400, 400);
|
||||
ImageView imageViewQrCode = (ImageView) findViewById(R.id.qrCode);
|
||||
imageViewQrCode.setImageBitmap(bitmap);
|
||||
} catch(Exception e) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
To customize the generated barcode image, use the `setBackgroundColor` and `setForegroundColor` functions of the
|
||||
`BarcodeEncoder` class with a [`@ColorInt`](https://developer.android.com/reference/androidx/annotation/ColorInt)
|
||||
value to update the background and foreground colors of the barcode respectively. By default, the barcode has a
|
||||
white background and black foreground.
|
||||
|
||||
|
||||
### Changing the orientation
|
||||
|
||||
@@ -94,9 +194,9 @@ Sample:
|
||||
```
|
||||
|
||||
```java
|
||||
IntentIntegrator integrator = new IntentIntegrator(this);
|
||||
integrator.setOrientationLocked(false);
|
||||
integrator.initiateScan();
|
||||
ScanOptions options = new ScanOptions();
|
||||
options.setOrientationLocked(false);
|
||||
barcodeLauncher.launch(options);
|
||||
```
|
||||
|
||||
### Customization and advanced options
|
||||
@@ -106,6 +206,8 @@ See [EMBEDDING](EMBEDDING.md).
|
||||
For more advanced options, look at the [Sample Application](https://github.com/journeyapps/zxing-android-embedded/blob/master/sample/src/main/java/example/zxing/MainActivity.java),
|
||||
and browse the source code of the library.
|
||||
|
||||
This is considered advanced usage, and is not well-documented or supported.
|
||||
|
||||
## Android Permissions
|
||||
|
||||
The camera permission is required for barcode scanning to function. It is automatically included as
|
||||
@@ -131,17 +233,30 @@ You can then use your local version by specifying in your `build.gradle` file:
|
||||
|
||||
## Sponsored by
|
||||
|
||||
[JourneyApps][1] - Creating business solutions with mobile apps. Fast.
|
||||
[JourneyApps][1]
|
||||
|
||||
|
||||
## License
|
||||
|
||||
[Apache License 2.0][7]
|
||||
Licensed under the [Apache License 2.0][7]
|
||||
|
||||
Copyright (C) 2012-2022 ZXing authors, Journey Mobile
|
||||
|
||||
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.
|
||||
|
||||
|
||||
|
||||
[1]: http://journeyapps.com
|
||||
[2]: https://github.com/zxing/zxing/
|
||||
[3]: https://github.com/zxing/zxing/wiki/Scanning-Via-Intent
|
||||
[4]: https://github.com/journeyapps/zxing-android-embedded/blob/2.x/README.md
|
||||
[5]: zxing-android-embedded/src/com/google/zxing/integration/android/IntentIntegrator.java
|
||||
[5]: zxing-android-embedded/src/com/journeyapps/barcodescanner/ScanOptions.java
|
||||
[7]: http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
+8
-11
@@ -1,27 +1,24 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven { url 'https://jitpack.io' } // for sdk-manager-plugin
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.1.0'
|
||||
classpath 'com.github.JakeWharton:sdk-manager-plugin:220bf7a88a7072df3ed16dc8466fb144f2817070'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
|
||||
classpath 'com.android.tools.build:gradle:7.0.3'
|
||||
}
|
||||
}
|
||||
|
||||
subprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
google()
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
version = '3.3.0'
|
||||
version = '4.3.0'
|
||||
group = 'com.journeyapps'
|
||||
apply plugin: 'android-sdk-manager'
|
||||
|
||||
ext.androidBuildTools = '23.0.2'
|
||||
ext.androidTargetSdk = 23
|
||||
ext.zxingCore = 'com.google.zxing:core:3.2.1'
|
||||
ext.androidTargetSdk = 30
|
||||
ext.zxingCore = 'com.google.zxing:core:3.4.1'
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
android.enableJetifier=false
|
||||
android.useAndroidX=true
|
||||
org.gradle.jvmargs=-Xmx1536M
|
||||
Vendored
BIN
Binary file not shown.
+1
-2
@@ -1,6 +1,5 @@
|
||||
#Sat Dec 20 18:56:59 SAST 2014
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip
|
||||
|
||||
@@ -1,4 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://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.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
@@ -6,47 +22,6 @@
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
esac
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
||||
if $cygwin ; then
|
||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
fi
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
@@ -61,9 +36,49 @@ while [ -h "$PRG" ] ; do
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >&-
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >&-
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
@@ -90,7 +105,7 @@ location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
@@ -110,10 +125,11 @@ if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
@@ -138,27 +154,30 @@ if $cygwin ; then
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
||||
Vendored
+100
@@ -0,0 +1,100 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -1 +0,0 @@
|
||||
/build
|
||||
@@ -1,24 +0,0 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
|
||||
android {
|
||||
compileSdkVersion project.androidTargetSdk
|
||||
buildToolsVersion project.androidBuildTools
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 11
|
||||
targetSdkVersion project.androidTargetSdk
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile(project(':zxing-android-embedded')) { transitive = true }
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in /home/ralf/apps/android-studio/sdk/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="example.zxing" >
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name" >
|
||||
<activity
|
||||
android:name="example.zxing.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -1,107 +0,0 @@
|
||||
package example.zxing;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
}
|
||||
|
||||
public void scanBarcode(View view) {
|
||||
new IntentIntegrator((Activity)this).initiateScan();
|
||||
}
|
||||
|
||||
public void scanBarcodeCustomOptions(View view) {
|
||||
IntentIntegrator integrator = new IntentIntegrator(this);
|
||||
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
|
||||
integrator.initiateScan();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
||||
if(result != null) {
|
||||
if(result.getContents() == null) {
|
||||
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
// This is important, otherwise the result will not be passed to the fragment
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sample of scanning from a Fragment
|
||||
*/
|
||||
public static class ScanFragment extends Fragment {
|
||||
private String toast;
|
||||
|
||||
public ScanFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
displayToast();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_scan, container, false);
|
||||
Button scan = (Button) view.findViewById(R.id.scan_from_fragment);
|
||||
scan.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
scanFromFragment();
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
public void scanFromFragment() {
|
||||
IntentIntegrator.forFragment(this).initiateScan();
|
||||
}
|
||||
|
||||
private void displayToast() {
|
||||
if(getActivity() != null && toast != null) {
|
||||
Toast.makeText(getActivity(), toast, Toast.LENGTH_LONG).show();
|
||||
toast = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
||||
if(result != null) {
|
||||
if(result.getContents() == null) {
|
||||
toast = "Cancelled from fragment";
|
||||
} else {
|
||||
toast = "Scanned from fragment: " + result.getContents();
|
||||
}
|
||||
|
||||
// At this point we may or may not have a reference to the activity
|
||||
displayToast();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 7.5 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.7 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 24 KiB |
@@ -1,33 +0,0 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:orientation="vertical"
|
||||
tools:context="example.zxing.MainActivity">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/scan_barcode"
|
||||
android:onClick="scanBarcode"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/custom_options"
|
||||
android:onClick="scanBarcodeCustomOptions"/>
|
||||
|
||||
|
||||
<fragment
|
||||
android:tag="scan_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
android:name="example.zxing.MainActivity$ScanFragment" tools:layout="@layout/fragment_scan" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,16 +0,0 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
tools:context="example.zxing.MainActivity"
|
||||
tools:showIn="@layout/activity_main">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/scan_from_fragment"
|
||||
android:id="@+id/scan_from_fragment"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
|
||||
</resources>
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">ZXing Sample</string>
|
||||
<string name="scan_barcode">Scan Barcode</string>
|
||||
<string name="custom_options">Custom Options</string>
|
||||
<string name="scan_from_fragment">Scan from fragment</string>
|
||||
|
||||
</resources>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="android:Theme">
|
||||
|
||||
</style>
|
||||
</resources>
|
||||
@@ -1 +0,0 @@
|
||||
/build
|
||||
+49
-19
@@ -2,23 +2,32 @@ apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion project.androidTargetSdk
|
||||
buildToolsVersion project.androidBuildTools
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 9
|
||||
multiDexEnabled true
|
||||
minSdkVersion 19
|
||||
targetSdkVersion project.androidTargetSdk
|
||||
versionCode 330
|
||||
versionName "3.3.0"
|
||||
versionCode 411
|
||||
versionName "4.1.1"
|
||||
}
|
||||
|
||||
Properties properties = new Properties()
|
||||
properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||
def keystoreFile = properties.getProperty('keystore.file')
|
||||
def keystorePassword = properties.getProperty('keystore.password')
|
||||
def keystoreAlias = properties.getProperty('keystore.alias')
|
||||
def validConfig = keystoreFile != null && keystorePassword != null && keystoreAlias != null;
|
||||
def validConfig
|
||||
def keystoreFile
|
||||
def keystorePassword
|
||||
def keystoreAlias
|
||||
|
||||
if(validConfig) {
|
||||
try {
|
||||
Properties properties = new Properties()
|
||||
properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||
keystoreFile = properties.getProperty('keystore.file')
|
||||
keystorePassword = properties.getProperty('keystore.password')
|
||||
keystoreAlias = properties.getProperty('keystore.alias')
|
||||
validConfig = keystoreFile != null && keystorePassword != null && keystoreAlias != null
|
||||
} catch (error) {
|
||||
validConfig = false
|
||||
}
|
||||
|
||||
if (validConfig) {
|
||||
System.out.println("Release signing configured with " + keystoreFile)
|
||||
signingConfigs {
|
||||
release {
|
||||
@@ -34,7 +43,7 @@ android {
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
if(validConfig) {
|
||||
if (validConfig) {
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
|
||||
@@ -42,18 +51,39 @@ android {
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
coreLibraryDesugaringEnabled true
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
// Error: The lint detector
|
||||
// androidx.appcompat.view.OnClickXmlDetector
|
||||
// called context.getMainProject() during module analysis.
|
||||
disable 'UsingOnClickInXml'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
// If you use this from an external project, use the following instead:
|
||||
// compile 'com.journeyapps:zxing-android-embedded:<version>@aar'
|
||||
// compile 'com.google.zxing:core:3.2.0'
|
||||
compile(project(':zxing-android-embedded')) { transitive = true }
|
||||
compile 'com.android.support:appcompat-v7:23.1.0'
|
||||
// implementation 'com.journeyapps:zxing-android-embedded:<version>'
|
||||
implementation project(':zxing-android-embedded')
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
|
||||
implementation "androidx.activity:activity:1.3.1"
|
||||
|
||||
// For development purposes only
|
||||
// Desugaring and multidex is required for API < 21.
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
|
||||
implementation 'androidx.multidex:multidex:2.0.1'
|
||||
|
||||
// leakcanary is for development purposes only
|
||||
// https://github.com/square/leakcanary
|
||||
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
|
||||
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
|
||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
|
||||
|
||||
// AboutLibraries
|
||||
implementation 'com.mikepenz:aboutlibraries:6.2.3'
|
||||
}
|
||||
|
||||
@@ -1,59 +1,52 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="example.zxing" >
|
||||
package="example.zxing">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:name=".SampleApplication"
|
||||
android:allowBackup="false"
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name"
|
||||
android:name=".SampleApplication">
|
||||
android:label="@string/app_name">
|
||||
<activity
|
||||
android:name="example.zxing.MainActivity"
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
android:theme="@style/AppTheme">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ContinuousCaptureActivity">
|
||||
|
||||
</activity>
|
||||
|
||||
<activity android:name=".AnyOrientationCaptureActivity"
|
||||
android:screenOrientation="fullSensor"
|
||||
android:stateNotNeeded="true"
|
||||
android:theme="@style/zxing_CaptureTheme"
|
||||
android:windowSoftInputMode="stateAlwaysHidden">
|
||||
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ToolbarCaptureActivity"
|
||||
android:clearTaskOnLaunch="true"
|
||||
android:screenOrientation="portrait"
|
||||
android:stateNotNeeded="true"
|
||||
android:theme="@style/AppCompatCaptureTheme"
|
||||
android:windowSoftInputMode="stateAlwaysHidden">
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ContinuousCaptureActivity"></activity>
|
||||
<activity
|
||||
android:name=".AnyOrientationCaptureActivity"
|
||||
android:screenOrientation="fullSensor"
|
||||
android:stateNotNeeded="true"
|
||||
android:theme="@style/zxing_CaptureTheme"
|
||||
android:windowSoftInputMode="stateAlwaysHidden"></activity>
|
||||
<activity
|
||||
android:name=".ToolbarCaptureActivity"
|
||||
android:clearTaskOnLaunch="true"
|
||||
android:screenOrientation="portrait"
|
||||
android:stateNotNeeded="true"
|
||||
android:theme="@style/AppCompatCaptureTheme"
|
||||
android:windowSoftInputMode="stateAlwaysHidden"></activity>
|
||||
<activity
|
||||
android:name=".CustomScannerActivity"
|
||||
android:screenOrientation="fullSensor"
|
||||
android:stateNotNeeded="true"
|
||||
android:theme="@style/zxing_CaptureTheme"
|
||||
android:windowSoftInputMode="stateAlwaysHidden">
|
||||
</activity>
|
||||
|
||||
android:windowSoftInputMode="stateAlwaysHidden"></activity>
|
||||
<activity
|
||||
android:name=".SmallCaptureActivity"
|
||||
android:screenOrientation="fullSensor"
|
||||
android:stateNotNeeded="true"
|
||||
android:theme="@style/zxing_CaptureTheme"
|
||||
android:windowSoftInputMode="stateAlwaysHidden">
|
||||
</activity>
|
||||
|
||||
android:windowSoftInputMode="stateAlwaysHidden"></activity>
|
||||
<activity
|
||||
android:name=".TabbedScanning"
|
||||
android:theme="@style/Theme.AppCompat"
|
||||
android:label="@string/title_activity_tabbed_scanning"></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
@@ -7,11 +7,16 @@ import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.client.android.BeepManager;
|
||||
import com.journeyapps.barcodescanner.BarcodeCallback;
|
||||
import com.journeyapps.barcodescanner.BarcodeResult;
|
||||
import com.journeyapps.barcodescanner.DecoratedBarcodeView;
|
||||
import com.journeyapps.barcodescanner.DefaultDecoderFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -19,17 +24,25 @@ import java.util.List;
|
||||
* a barcode is scanned.
|
||||
*/
|
||||
public class ContinuousCaptureActivity extends Activity {
|
||||
private static final String TAG = ContinuousCaptureActivity.class.getSimpleName();
|
||||
private DecoratedBarcodeView barcodeView;
|
||||
private BeepManager beepManager;
|
||||
private String lastText;
|
||||
|
||||
private BarcodeCallback callback = new BarcodeCallback() {
|
||||
@Override
|
||||
public void barcodeResult(BarcodeResult result) {
|
||||
if (result.getText() != null) {
|
||||
barcodeView.setStatusText(result.getText());
|
||||
if(result.getText() == null || result.getText().equals(lastText)) {
|
||||
// Prevent duplicate scans
|
||||
return;
|
||||
}
|
||||
|
||||
lastText = result.getText();
|
||||
barcodeView.setStatusText(result.getText());
|
||||
|
||||
beepManager.playBeepSoundAndVibrate();
|
||||
|
||||
//Added preview of scanned barcode
|
||||
ImageView imageView = (ImageView) findViewById(R.id.barcodePreview);
|
||||
ImageView imageView = findViewById(R.id.barcodePreview);
|
||||
imageView.setImageBitmap(result.getBitmapWithResultPoints(Color.YELLOW));
|
||||
}
|
||||
|
||||
@@ -44,8 +57,13 @@ public class ContinuousCaptureActivity extends Activity {
|
||||
|
||||
setContentView(R.layout.continuous_scan);
|
||||
|
||||
barcodeView = (DecoratedBarcodeView) findViewById(R.id.barcode_scanner);
|
||||
barcodeView = findViewById(R.id.barcode_scanner);
|
||||
Collection<BarcodeFormat> formats = Arrays.asList(BarcodeFormat.QR_CODE, BarcodeFormat.CODE_39);
|
||||
barcodeView.getBarcodeView().setDecoderFactory(new DefaultDecoderFactory(formats));
|
||||
barcodeView.initializeFromIntent(getIntent());
|
||||
barcodeView.decodeContinuous(callback);
|
||||
|
||||
beepManager = new BeepManager(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,13 +2,19 @@ package example.zxing;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.journeyapps.barcodescanner.CaptureManager;
|
||||
import com.journeyapps.barcodescanner.DecoratedBarcodeView;
|
||||
import com.journeyapps.barcodescanner.ViewfinderView;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Custom Scannner Activity extending from Activity to display a custom layout form scanner view.
|
||||
@@ -19,16 +25,19 @@ public class CustomScannerActivity extends Activity implements
|
||||
private CaptureManager capture;
|
||||
private DecoratedBarcodeView barcodeScannerView;
|
||||
private Button switchFlashlightButton;
|
||||
private ViewfinderView viewfinderView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_custom_scanner);
|
||||
|
||||
barcodeScannerView = (DecoratedBarcodeView)findViewById(R.id.zxing_barcode_scanner);
|
||||
barcodeScannerView = findViewById(R.id.zxing_barcode_scanner);
|
||||
barcodeScannerView.setTorchListener(this);
|
||||
|
||||
switchFlashlightButton = (Button)findViewById(R.id.switch_flashlight);
|
||||
switchFlashlightButton = findViewById(R.id.switch_flashlight);
|
||||
|
||||
viewfinderView = findViewById(R.id.zxing_viewfinder_view);
|
||||
|
||||
// if the device does not have flashlight in its camera,
|
||||
// then remove the switch flashlight button...
|
||||
@@ -38,7 +47,11 @@ public class CustomScannerActivity extends Activity implements
|
||||
|
||||
capture = new CaptureManager(this, barcodeScannerView);
|
||||
capture.initializeFromIntent(getIntent(), savedInstanceState);
|
||||
capture.setShowMissingCameraPermissionDialog(false);
|
||||
capture.decode();
|
||||
|
||||
changeMaskColor(null);
|
||||
changeLaserVisibility(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,6 +100,16 @@ public class CustomScannerActivity extends Activity implements
|
||||
}
|
||||
}
|
||||
|
||||
public void changeMaskColor(View view) {
|
||||
Random rnd = new Random();
|
||||
int color = Color.argb(100, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
|
||||
viewfinderView.setMaskColor(color);
|
||||
}
|
||||
|
||||
public void changeLaserVisibility(boolean visible) {
|
||||
viewfinderView.setLaserVisibility(visible);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTorchOn() {
|
||||
switchFlashlightButton.setText(R.string.turn_off_flashlight);
|
||||
@@ -97,4 +120,8 @@ public class CustomScannerActivity extends Activity implements
|
||||
switchFlashlightButton.setText(R.string.turn_on_flashlight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
capture.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package example.zxing;
|
||||
import android.content.Intent;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -12,11 +10,34 @@ import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
import com.google.zxing.client.android.Intents;
|
||||
import com.journeyapps.barcodescanner.ScanContract;
|
||||
import com.journeyapps.barcodescanner.ScanOptions;
|
||||
import com.mikepenz.aboutlibraries.LibsBuilder;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
|
||||
public class MainActivity extends ActionBarActivity {
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private final ActivityResultLauncher<ScanOptions> barcodeLauncher = registerForActivityResult(new ScanContract(),
|
||||
result -> {
|
||||
if(result.getContents() == null) {
|
||||
Intent originalIntent = result.getOriginalIntent();
|
||||
if (originalIntent == null) {
|
||||
Log.d("MainActivity", "Cancelled scan");
|
||||
Toast.makeText(MainActivity.this, "Cancelled", Toast.LENGTH_LONG).show();
|
||||
} else if(originalIntent.hasExtra(Intents.Scan.MISSING_CAMERA_PERMISSION)) {
|
||||
Log.d("MainActivity", "Cancelled scan due to missing camera permission");
|
||||
Toast.makeText(MainActivity.this, "Cancelled due to missing camera permission", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
Log.d("MainActivity", "Scanned");
|
||||
Toast.makeText(MainActivity.this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -25,23 +46,45 @@ public class MainActivity extends ActionBarActivity {
|
||||
}
|
||||
|
||||
public void scanBarcode(View view) {
|
||||
new IntentIntegrator(this).initiateScan();
|
||||
barcodeLauncher.launch(new ScanOptions());
|
||||
}
|
||||
|
||||
public void scanBarcodeInverted(View view){
|
||||
ScanOptions options = new ScanOptions();
|
||||
options.addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.INVERTED_SCAN);
|
||||
barcodeLauncher.launch(options);
|
||||
}
|
||||
|
||||
public void scanMixedBarcodes(View view){
|
||||
ScanOptions options = new ScanOptions();
|
||||
options.addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.MIXED_SCAN);
|
||||
barcodeLauncher.launch(options);
|
||||
}
|
||||
|
||||
public void scanBarcodeCustomLayout(View view) {
|
||||
IntentIntegrator integrator = new IntentIntegrator(this);
|
||||
integrator.setCaptureActivity(AnyOrientationCaptureActivity.class);
|
||||
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
|
||||
integrator.setPrompt("Scan something");
|
||||
integrator.setOrientationLocked(false);
|
||||
integrator.setBeepEnabled(false);
|
||||
integrator.initiateScan();
|
||||
ScanOptions options = new ScanOptions();
|
||||
options.setCaptureActivity(AnyOrientationCaptureActivity.class);
|
||||
options.setDesiredBarcodeFormats(ScanOptions.ONE_D_CODE_TYPES);
|
||||
options.setPrompt("Scan something");
|
||||
options.setOrientationLocked(false);
|
||||
options.setBeepEnabled(false);
|
||||
barcodeLauncher.launch(options);
|
||||
}
|
||||
|
||||
public void scanPDF417(View view) {
|
||||
ScanOptions options = new ScanOptions();
|
||||
options.setDesiredBarcodeFormats(ScanOptions.PDF_417);
|
||||
options.setPrompt("Scan something");
|
||||
options.setOrientationLocked(false);
|
||||
options.setBeepEnabled(false);
|
||||
barcodeLauncher.launch(options);
|
||||
}
|
||||
|
||||
|
||||
public void scanBarcodeFrontCamera(View view) {
|
||||
IntentIntegrator integrator = new IntentIntegrator(this);
|
||||
integrator.setCameraId(Camera.CameraInfo.CAMERA_FACING_FRONT);
|
||||
integrator.initiateScan();
|
||||
ScanOptions options = new ScanOptions();
|
||||
options.setCameraId(Camera.CameraInfo.CAMERA_FACING_FRONT);
|
||||
barcodeLauncher.launch(options);
|
||||
}
|
||||
|
||||
public void scanContinuous(View view) {
|
||||
@@ -50,98 +93,64 @@ public class MainActivity extends ActionBarActivity {
|
||||
}
|
||||
|
||||
public void scanToolbar(View view) {
|
||||
new IntentIntegrator(this).setCaptureActivity(ToolbarCaptureActivity.class).initiateScan();
|
||||
ScanOptions options = new ScanOptions().setCaptureActivity(ToolbarCaptureActivity.class);
|
||||
barcodeLauncher.launch(options);
|
||||
}
|
||||
|
||||
public void scanCustomScanner(View view) {
|
||||
new IntentIntegrator(this).setOrientationLocked(false).setCaptureActivity(CustomScannerActivity.class).initiateScan();
|
||||
ScanOptions options = new ScanOptions().setOrientationLocked(false).setCaptureActivity(CustomScannerActivity.class);
|
||||
barcodeLauncher.launch(options);
|
||||
}
|
||||
|
||||
public void scanMarginScanner(View view) {
|
||||
IntentIntegrator integrator = new IntentIntegrator(this);
|
||||
integrator.setOrientationLocked(false);
|
||||
integrator.setCaptureActivity(SmallCaptureActivity.class);
|
||||
integrator.initiateScan();
|
||||
ScanOptions options = new ScanOptions();
|
||||
options.setOrientationLocked(false);
|
||||
options.setCaptureActivity(SmallCaptureActivity.class);
|
||||
barcodeLauncher.launch(options);
|
||||
}
|
||||
|
||||
public void scanWithTimeout(View view) {
|
||||
IntentIntegrator integrator = new IntentIntegrator(this);
|
||||
integrator.setTimeout(8000);
|
||||
integrator.initiateScan();
|
||||
ScanOptions options = new ScanOptions();
|
||||
options.setTimeout(8000);
|
||||
barcodeLauncher.launch(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
||||
if(result != null) {
|
||||
if(result.getContents() == null) {
|
||||
Log.d("MainActivity", "Cancelled scan");
|
||||
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Log.d("MainActivity", "Scanned");
|
||||
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
// This is important, otherwise the result will not be passed to the fragment
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
public void tabs(View view) {
|
||||
Intent intent = new Intent(this, TabbedScanning.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public void about(View view) {
|
||||
new LibsBuilder().start(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sample of scanning from a Fragment
|
||||
*/
|
||||
public static class ScanFragment extends Fragment {
|
||||
private String toast;
|
||||
private final ActivityResultLauncher<ScanOptions> fragmentLauncher = registerForActivityResult(new ScanContract(),
|
||||
result -> {
|
||||
if(result.getContents() == null) {
|
||||
Toast.makeText(getContext(), "Cancelled from fragment", Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(getContext(), "Scanned from fragment: " + result.getContents(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
public ScanFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
displayToast();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_scan, container, false);
|
||||
Button scan = (Button) view.findViewById(R.id.scan_from_fragment);
|
||||
scan.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
scanFromFragment();
|
||||
}
|
||||
});
|
||||
Button scan = view.findViewById(R.id.scan_from_fragment);
|
||||
scan.setOnClickListener(v -> scanFromFragment());
|
||||
return view;
|
||||
}
|
||||
|
||||
public void scanFromFragment() {
|
||||
IntentIntegrator.forSupportFragment(this).initiateScan();
|
||||
}
|
||||
|
||||
private void displayToast() {
|
||||
if(getActivity() != null && toast != null) {
|
||||
Toast.makeText(getActivity(), toast, Toast.LENGTH_LONG).show();
|
||||
toast = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
||||
if(result != null) {
|
||||
if(result.getContents() == null) {
|
||||
toast = "Cancelled from fragment";
|
||||
} else {
|
||||
toast = "Scanned from fragment: " + result.getContents();
|
||||
}
|
||||
|
||||
// At this point we may or may not have a reference to the activity
|
||||
displayToast();
|
||||
}
|
||||
fragmentLauncher.launch(new ScanOptions());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
package example.zxing;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.squareup.leakcanary.LeakCanary;
|
||||
import androidx.multidex.MultiDexApplication;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SampleApplication extends Application {
|
||||
public class SampleApplication extends MultiDexApplication {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
LeakCanary.install(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
package example.zxing;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.legacy.app.FragmentStatePagerAdapter;
|
||||
import androidx.viewpager.widget.PagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.journeyapps.barcodescanner.CameraPreview;
|
||||
import com.journeyapps.barcodescanner.DecoratedBarcodeView;
|
||||
|
||||
public class TabbedScanning extends AppCompatActivity implements ActionBar.TabListener {
|
||||
|
||||
/**
|
||||
* The {@link PagerAdapter} that will provide
|
||||
* fragments for each of the sections. We use a
|
||||
* {@link FragmentPagerAdapter} derivative, which will keep every
|
||||
* loaded fragment in memory. If this becomes too memory intensive, it
|
||||
* may be best to switch to a
|
||||
* {@link FragmentStatePagerAdapter}.
|
||||
*/
|
||||
private SectionsPagerAdapter mSectionsPagerAdapter;
|
||||
|
||||
|
||||
/**
|
||||
* The {@link ViewPager} that will host the section contents.
|
||||
*/
|
||||
private ViewPager mViewPager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_tabbed_scanning);
|
||||
// Create the adapter that will return a fragment for each of the three
|
||||
// primary sections of the activity.
|
||||
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
|
||||
// Set up the ViewPager with the sections adapter.
|
||||
mViewPager = findViewById(R.id.container);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
|
||||
// Set up the action bar.
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
|
||||
// When swiping between different sections, select the corresponding
|
||||
// tab. We can also use ActionBar.Tab#select() to do this if we have
|
||||
// a reference to the Tab.
|
||||
mViewPager.setOffscreenPageLimit(0);
|
||||
mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
actionBar.setSelectedNavigationItem(position);
|
||||
}
|
||||
});
|
||||
|
||||
// For each of the sections in the app, add a tab to the action bar.
|
||||
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
|
||||
// Create a tab with text corresponding to the page title defined by
|
||||
// the adapter. Also specify this Activity object, which implements
|
||||
// the TabListener interface, as the callback (listener) for when
|
||||
// this tab is selected.
|
||||
actionBar.addTab(
|
||||
actionBar.newTab()
|
||||
.setText(mSectionsPagerAdapter.getPageTitle(i))
|
||||
.setTabListener(this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
|
||||
// When the given tab is selected, switch to the corresponding page in
|
||||
// the ViewPager.
|
||||
mViewPager.setCurrentItem(tab.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
public static class ScanFragment extends Fragment {
|
||||
DecoratedBarcodeView barcodeView;
|
||||
|
||||
public ScanFragment() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance of this fragment for the given section
|
||||
* number.
|
||||
*/
|
||||
public static ScanFragment newInstance() {
|
||||
return new ScanFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_tabbed_scanning, container, false);
|
||||
barcodeView = rootView.findViewById(R.id.barcode_view);
|
||||
return rootView;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if(barcodeView != null) {
|
||||
if (isVisibleToUser) {
|
||||
barcodeView.resume();
|
||||
} else {
|
||||
barcodeView.pauseAndWait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
barcodeView.pauseAndWait();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
barcodeView.resume();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
public static class CameraFragment extends Fragment {
|
||||
|
||||
private CameraPreview cameraPreview;
|
||||
|
||||
public CameraFragment() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance of this fragment for the given section
|
||||
* number.
|
||||
*/
|
||||
public static CameraFragment newInstance() {
|
||||
return new CameraFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_tabbed_camera, container, false);
|
||||
cameraPreview = rootView.findViewById(R.id.camera_preview);
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
|
||||
if (cameraPreview != null) {
|
||||
if (isVisibleToUser) {
|
||||
cameraPreview.resume();
|
||||
} else {
|
||||
cameraPreview.pauseAndWait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
cameraPreview.pauseAndWait();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
|
||||
* one of the sections/tabs/pages.
|
||||
*/
|
||||
public class SectionsPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
if(position == 0) {
|
||||
return ScanFragment.newInstance();
|
||||
} else {
|
||||
return CameraFragment.newInstance();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return "Scan";
|
||||
case 1:
|
||||
return "Camera";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package example.zxing;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.journeyapps.barcodescanner.CaptureManager;
|
||||
@@ -11,7 +11,7 @@ import com.journeyapps.barcodescanner.DecoratedBarcodeView;
|
||||
/**
|
||||
* Sample Activity extending from ActionBarActivity to display a Toolbar.
|
||||
*/
|
||||
public class ToolbarCaptureActivity extends ActionBarActivity {
|
||||
public class ToolbarCaptureActivity extends AppCompatActivity {
|
||||
private CaptureManager capture;
|
||||
private DecoratedBarcodeView barcodeScannerView;
|
||||
|
||||
@@ -20,12 +20,12 @@ public class ToolbarCaptureActivity extends ActionBarActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.capture_appcompat);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
|
||||
Toolbar toolbar = findViewById(R.id.my_awesome_toolbar);
|
||||
toolbar.setTitle("Scan Barcode");
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
barcodeScannerView = (DecoratedBarcodeView)findViewById(R.id.zxing_barcode_scanner);
|
||||
barcodeScannerView = findViewById(R.id.zxing_barcode_scanner);
|
||||
|
||||
capture = new CaptureManager(this, barcodeScannerView);
|
||||
capture.initializeFromIntent(getIntent(), savedInstanceState);
|
||||
|
||||
@@ -19,6 +19,24 @@
|
||||
android:text="@string/scan_barcode"
|
||||
android:onClick="scanBarcode"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Scan PDF417"
|
||||
android:onClick="scanPDF417"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Scan Inverted"
|
||||
android:onClick="scanBarcodeInverted"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Scan Normal and Inverted"
|
||||
android:onClick="scanMixedBarcodes"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -69,6 +87,19 @@
|
||||
android:text="@string/scanner_with_timeout"
|
||||
android:onClick="scanWithTimeout"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/tabs"
|
||||
android:onClick="tabs"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/about"
|
||||
android:onClick="about"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<androidx.viewpager.widget.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="example.zxing.TabbedScanning" />
|
||||
@@ -22,7 +22,7 @@
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/my_awesome_toolbar"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
app:zxing_possible_result_points="@color/zxing_custom_possible_result_points"
|
||||
app:zxing_result_view="@color/zxing_custom_result_view"
|
||||
app:zxing_viewfinder_laser="@color/zxing_custom_viewfinder_laser"
|
||||
app:zxing_viewfinder_laser_visibility="true"
|
||||
app:zxing_viewfinder_mask="@color/zxing_custom_viewfinder_mask"/>
|
||||
|
||||
<TextView
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="example.zxing.TabbedScanning$CameraFragment">
|
||||
|
||||
<com.journeyapps.barcodescanner.CameraPreview
|
||||
android:id="@+id/camera_preview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="300dp"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -0,0 +1,18 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="example.zxing.TabbedScanning$ScanFragment">
|
||||
|
||||
|
||||
<com.journeyapps.barcodescanner.DecoratedBarcodeView
|
||||
android:id="@+id/barcode_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -0,0 +1,4 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="example.zxing.TabbedScanning">
|
||||
</menu>
|
||||
@@ -0,0 +1,6 @@
|
||||
<resources>
|
||||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
||||
(such as screen margins) for screens with more than 820dp of available width. This
|
||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||
</resources>
|
||||
@@ -1,8 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
|
||||
|
||||
<string name="app_name">ZXing Sample</string>
|
||||
<string name="scan_barcode">Scan Barcode</string>
|
||||
<string name="scan_barcode_with_request_code">Scan Barcode with customized request code</string>
|
||||
<string name="any_orientation">1D Any Orientation</string>
|
||||
<string name="scan_from_fragment">Scan from fragment</string>
|
||||
<string name="front_camera">Front Camera</string>
|
||||
@@ -13,5 +14,8 @@
|
||||
<string name="scanner_with_timeout">Finish Scan in 8 Seconds</string>
|
||||
<string name="turn_on_flashlight">Turn on Flashlight</string>
|
||||
<string name="turn_off_flashlight">Turn off Flashlight</string>
|
||||
<string name="title_activity_tabbed_scanning">Tabbed Scanning</string>
|
||||
<string name="tabs">Tabs</string>
|
||||
<string name="about">About</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
include ':zxing-android-embedded'
|
||||
include ':sample'
|
||||
include ':sample-nosupport'
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
|
||||
<!-- Support Android 2.3+. -->
|
||||
<uses-sdk android:minSdkVersion="9" />
|
||||
|
||||
<!-- Don't require camera, as this requires a rear camera. This allows it to work on the Nexus 7 -->
|
||||
<uses-feature android:name="android.hardware.camera" android:required="false"/>
|
||||
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
|
||||
|
||||
@@ -1,24 +1,48 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
|
||||
apply plugin: 'signing'
|
||||
|
||||
ext.artifactId = 'zxing-android-embedded'
|
||||
|
||||
dependencies {
|
||||
compile project.zxingCore
|
||||
|
||||
compile 'com.android.support:support-v4:23.1.0'
|
||||
// Publishing config from https://getstream.io/blog/publishing-libraries-to-mavencentral-2021/
|
||||
ext["signing.keyId"] = ''
|
||||
ext["signing.password"] = ''
|
||||
ext["signing.secretKeyRingFile"] = ''
|
||||
ext["ossrhUsername"] = ''
|
||||
ext["ossrhPassword"] = ''
|
||||
ext["sonatypeStagingProfileId"] = ''
|
||||
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile "org.mockito:mockito-core:1.9.5"
|
||||
File secretPropsFile = project.rootProject.file('local.properties')
|
||||
if (secretPropsFile.exists()) {
|
||||
Properties p = new Properties()
|
||||
p.load(new FileInputStream(secretPropsFile))
|
||||
p.each { name, value ->
|
||||
ext[name] = value
|
||||
}
|
||||
} else {
|
||||
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
|
||||
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
|
||||
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
|
||||
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
|
||||
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
|
||||
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
api project.zxingCore
|
||||
|
||||
implementation 'androidx.core:core:1.6.0'
|
||||
implementation 'androidx.fragment:fragment:1.3.6'
|
||||
|
||||
testImplementation 'junit:junit:4.13.1'
|
||||
testImplementation 'org.mockito:mockito-core:1.9.5'
|
||||
}
|
||||
|
||||
android {
|
||||
resourcePrefix 'zxing_'
|
||||
compileSdkVersion project.androidTargetSdk
|
||||
buildToolsVersion project.androidBuildTools
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
@@ -27,7 +51,7 @@ android {
|
||||
res.srcDirs = ['res-orig', 'res']
|
||||
assets.srcDirs = ['assets']
|
||||
}
|
||||
test.setRoot('test');
|
||||
test.setRoot('test')
|
||||
}
|
||||
|
||||
// This is bad practice - we should fix the warnings instead.
|
||||
@@ -38,14 +62,28 @@ android {
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
targetCompatibility JavaVersion.VERSION_1_7
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
testOptions {
|
||||
// We test with primitives such as Rect, and rely on their default behaviour working.
|
||||
unitTests.returnDefaultValues = true
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
versionNameSuffix ".debug"
|
||||
resValue "string", "app_version", "${defaultConfig.versionName}${versionNameSuffix}"
|
||||
}
|
||||
release {
|
||||
resValue "string", "app_version", "${defaultConfig.versionName}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task sourceJar(type: Jar) {
|
||||
@@ -53,15 +91,43 @@ task sourceJar(type: Jar) {
|
||||
from android.sourceSets.main.java.srcDirs
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
// We need this check to cover Android Studio gradle sync
|
||||
if(project.tasks.findByPath('bundleRelease') != null) {
|
||||
project.afterEvaluate {
|
||||
publishing {
|
||||
publications {
|
||||
maven(MavenPublication) {
|
||||
artifact bundleRelease
|
||||
artifact bundleReleaseAar
|
||||
artifactId project.artifactId
|
||||
|
||||
artifact sourceJar
|
||||
|
||||
pom {
|
||||
name = project.artifactId
|
||||
description = 'Barcode scanner library for Android, based on the ZXing decoder'
|
||||
url = 'https://github.com/journeyapps/zxing-android-embedded'
|
||||
|
||||
licenses {
|
||||
license {
|
||||
name = 'The Apache License, Version 2.0'
|
||||
url = 'https://github.com/journeyapps/zxing-android-embedded/blob/master/COPYING'
|
||||
}
|
||||
}
|
||||
|
||||
developers {
|
||||
developer {
|
||||
id = ''
|
||||
name = 'Ralf Kistner'
|
||||
email = 'ralf@journeyapps.com'
|
||||
organization = 'Journey Mobile, Inc'
|
||||
organizationUrl = 'https://journeyapps.com'
|
||||
}
|
||||
}
|
||||
scm {
|
||||
connection = 'scm:git:github.com/journeyapps/zxing-android-embedded.git'
|
||||
developerConnection = 'scm:git:ssh://github.com/journeyapps/zxing-android-embedded.git'
|
||||
url = 'https://github.com/journeyapps/zxing-android-embedded'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pom.withXml {
|
||||
// HACK to add dependencies to POM.
|
||||
@@ -69,35 +135,31 @@ publishing {
|
||||
// remove this section.
|
||||
def deps = asNode().appendNode('dependencies')
|
||||
|
||||
project.configurations.compile.allDependencies.each { dep ->
|
||||
project.configurations.api.allDependencies.each { dep ->
|
||||
def node = deps.appendNode('dependency')
|
||||
node.appendNode('groupId', dep.group)
|
||||
node.appendNode('artifactId', dep.name)
|
||||
node.appendNode('version', dep.version)
|
||||
node.appendNode('scope', 'compile')
|
||||
node.appendNode('scope', 'api')
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "sonatype"
|
||||
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
|
||||
credentials {
|
||||
username ossrhUsername
|
||||
password ossrhPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// To release, place bintray_user and bintray_key properties in ~/.gradle/gradle.properties,
|
||||
// and run ./gradlew clean assembleRelease bintrayUpload
|
||||
|
||||
if(project.hasProperty('bintray_user') && project.hasProperty('bintray_key')) {
|
||||
bintray {
|
||||
user = bintray_user
|
||||
key = bintray_key
|
||||
publications = ['maven']
|
||||
publish = true
|
||||
pkg {
|
||||
userOrg = 'journeyapps'
|
||||
repo = 'maven'
|
||||
name = 'zxing-android-embedded'
|
||||
}
|
||||
}
|
||||
signing {
|
||||
sign publishing.publications
|
||||
}
|
||||
|
||||
|
||||
@@ -18,5 +18,5 @@
|
||||
<string name="zxing_app_name">Barcode Scanner</string>
|
||||
<string name="zxing_button_ok">D\'acord</string>
|
||||
<string name="zxing_msg_camera_framework_bug">S\'ha produït un problema amb la càmera de l\'Android. Potser haureu de reiniciar el dispositiu.</string>
|
||||
<string name="zxing_msg_default_status">Poseu un codi de barres dins el rectable per escanejar-lo.</string>
|
||||
<string name="zxing_msg_default_status">Poseu un codi de barres dins el rectangle per escanejar-lo.</string>
|
||||
</resources>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<com.journeyapps.barcodescanner.BarcodeView
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<!--
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<resources>
|
||||
<style name="zxing_CaptureTheme" parent="android:Theme.Holo.NoActionBar.Fullscreen">
|
||||
</style>
|
||||
</resources>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName,UnusedResources" >
|
||||
<string name="define_zxingandroidembedded" translatable="false" />
|
||||
<!-- Author section -->
|
||||
<string name="library_zxingandroidembedded_author" translatable="false">JourneyApps</string>
|
||||
<string name="library_zxingandroidembedded_authorWebsite" translatable="false">https://journeyapps.com/</string>
|
||||
<!-- Library section -->
|
||||
<string name="library_zxingandroidembedded_libraryName" translatable="false">ZXing Android Embedded</string>
|
||||
<string name="library_zxingandroidembedded_libraryDescription" translatable="false">Barcode scanning library for Android, using ZXing for decoding.</string>
|
||||
<string name="library_zxingandroidembedded_libraryWebsite" translatable="false">https://github.com/journeyapps/zxing-android-embedded</string>
|
||||
<string name="library_zxingandroidembedded_libraryVersion" translatable="false" />
|
||||
<!-- OpenSource section -->
|
||||
<string name="library_zxingandroidembedded_isOpenSource" translatable="false">true</string>
|
||||
<string name="library_zxingandroidembedded_repositoryLink" translatable="false">https://github.com/journeyapps/zxing-android-embedded</string>
|
||||
<!-- License section -->
|
||||
<string name="library_zxingandroidembedded_licenseId" translatable="false">apache_2_0</string>
|
||||
<!-- Custom variables section -->
|
||||
</resources>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<attr name="zxing_result_view" format="color"/>
|
||||
<attr name="zxing_viewfinder_laser" format="color"/>
|
||||
<attr name="zxing_viewfinder_mask" format="color"/>
|
||||
<attr name="zxing_viewfinder_laser_visibility" format="boolean"/>
|
||||
</declare-styleable>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
-->
|
||||
<resources>
|
||||
<item type="id" name="zxing_decode"/>
|
||||
<item type="id" name="zxing_preview_failed"/>
|
||||
<item type="id" name="zxing_decode_failed"/>
|
||||
<item type="id" name="zxing_decode_succeeded"/>
|
||||
<item type="id" name="zxing_possible_result_points"/>
|
||||
<item type="id" name="zxing_back_button"/>
|
||||
<item type="id" name="zxing_prewiew_size_ready"/>
|
||||
<item type="id" name="zxing_camera_error"/>
|
||||
<item type="id" name="zxing_camera_closed"/>
|
||||
</resources>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<resources>
|
||||
<style name="zxing_CaptureTheme" parent="android:Theme.Black.NoTitleBar.Fullscreen">
|
||||
<style name="zxing_CaptureTheme" parent="android:Theme.Holo.NoActionBar.Fullscreen">
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
@@ -71,12 +71,7 @@ public final class AmbientLightManager implements SensorEventListener {
|
||||
}
|
||||
|
||||
private void setTorch(final boolean on) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cameraManager.setTorch(on);
|
||||
}
|
||||
});
|
||||
handler.post(() -> cameraManager.setTorch(on));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,5 +90,4 @@ public final class AmbientLightManager implements SensorEventListener {
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,39 +16,39 @@
|
||||
|
||||
package com.google.zxing.client.android;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Build;
|
||||
import android.os.Vibrator;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Manages beeps and vibrations.
|
||||
*/
|
||||
public final class BeepManager implements
|
||||
MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, Closeable {
|
||||
public final class BeepManager {
|
||||
|
||||
private static final String TAG = BeepManager.class.getSimpleName();
|
||||
|
||||
private static final float BEEP_VOLUME = 0.10f;
|
||||
private static final long VIBRATE_DURATION = 200L;
|
||||
|
||||
private final Activity activity;
|
||||
private MediaPlayer mediaPlayer;
|
||||
private boolean playBeep;
|
||||
private final Context context;
|
||||
|
||||
private boolean beepEnabled = true;
|
||||
private boolean vibrateEnabled = false;
|
||||
|
||||
public BeepManager(Activity activity) {
|
||||
this.activity = activity;
|
||||
this.mediaPlayer = null;
|
||||
updatePrefs();
|
||||
activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
|
||||
// We do not keep a reference to the Activity itself, to prevent leaks
|
||||
this.context = activity.getApplicationContext();
|
||||
}
|
||||
|
||||
public boolean isBeepEnabled() {
|
||||
@@ -79,45 +79,44 @@ public final class BeepManager implements
|
||||
this.vibrateEnabled = vibrateEnabled;
|
||||
}
|
||||
|
||||
public synchronized void updatePrefs() {
|
||||
playBeep = shouldBeep(beepEnabled, activity);
|
||||
if (playBeep && mediaPlayer == null) {
|
||||
// The volume on STREAM_SYSTEM is not adjustable, and users found it too loud,
|
||||
// so we now play on the music stream.
|
||||
activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
mediaPlayer = buildMediaPlayer(activity);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public synchronized void playBeepSoundAndVibrate() {
|
||||
if (playBeep && mediaPlayer != null) {
|
||||
mediaPlayer.start();
|
||||
if (beepEnabled) {
|
||||
playBeepSound();
|
||||
}
|
||||
if (vibrateEnabled) {
|
||||
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vibrator.vibrate(VIBRATE_DURATION);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldBeep(boolean beep, Context activity) {
|
||||
boolean shouldPlayBeep = beep;
|
||||
if (shouldPlayBeep) {
|
||||
// See if sound settings overrides this
|
||||
AudioManager audioService = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
|
||||
if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
|
||||
shouldPlayBeep = false;
|
||||
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
if (vibrator != null) {
|
||||
vibrator.vibrate(VIBRATE_DURATION);
|
||||
}
|
||||
}
|
||||
return shouldPlayBeep;
|
||||
}
|
||||
|
||||
private MediaPlayer buildMediaPlayer(Context activity) {
|
||||
|
||||
public MediaPlayer playBeepSound() {
|
||||
MediaPlayer mediaPlayer = new MediaPlayer();
|
||||
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||
mediaPlayer.setOnCompletionListener(this);
|
||||
mediaPlayer.setOnErrorListener(this);
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
mediaPlayer.setAudioAttributes(new AudioAttributes.Builder().setContentType(
|
||||
AudioAttributes.CONTENT_TYPE_MUSIC).build());
|
||||
} else {
|
||||
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||
}
|
||||
|
||||
mediaPlayer.setOnCompletionListener(mp -> {
|
||||
mp.stop();
|
||||
mp.reset();
|
||||
mp.release();
|
||||
});
|
||||
mediaPlayer.setOnErrorListener((mp, what, extra) -> {
|
||||
Log.w(TAG, "Failed to beep " + what + ", " + extra);
|
||||
// possibly media player error, so release and recreate
|
||||
mp.stop();
|
||||
mp.reset();
|
||||
mp.release();
|
||||
return true;
|
||||
});
|
||||
try {
|
||||
AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.zxing_beep);
|
||||
AssetFileDescriptor file = context.getResources().openRawResourceFd(R.raw.zxing_beep);
|
||||
try {
|
||||
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
|
||||
} finally {
|
||||
@@ -125,40 +124,13 @@ public final class BeepManager implements
|
||||
}
|
||||
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
|
||||
mediaPlayer.prepare();
|
||||
mediaPlayer.start();
|
||||
return mediaPlayer;
|
||||
} catch (IOException ioe) {
|
||||
Log.w(TAG, ioe);
|
||||
mediaPlayer.reset();
|
||||
mediaPlayer.release();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
// When the beep has finished playing, rewind to queue up another one.
|
||||
mp.seekTo(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
|
||||
if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
|
||||
// we are finished, so put up an appropriate error toast if required and finish
|
||||
activity.finish();
|
||||
} else {
|
||||
// possibly media player error, so release and recreate
|
||||
mp.release();
|
||||
mediaPlayer = null;
|
||||
updatePrefs();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
if (mediaPlayer != null) {
|
||||
mediaPlayer.release();
|
||||
mediaPlayer = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,14 +17,12 @@
|
||||
package com.google.zxing.client.android;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -98,5 +96,4 @@ public final class DecodeFormatManager {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -233,5 +233,4 @@ public final class DecodeHintManager {
|
||||
Log.i(TAG, "Hints from the Intent: " + hints);
|
||||
return hints;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -108,12 +108,7 @@ public final class InactivityTimer {
|
||||
// 0 indicates that we're on battery
|
||||
final boolean onBatteryNow = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) <= 0;
|
||||
// post on handler to run in main thread
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onBattery(onBatteryNow);
|
||||
}
|
||||
});
|
||||
handler.post(() -> onBattery(onBatteryNow));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +88,13 @@ public final class Intents {
|
||||
*/
|
||||
public static final String CAMERA_ID = "SCAN_CAMERA_ID";
|
||||
|
||||
/**
|
||||
* Optional parameter to switch the torch on at camera startup.
|
||||
* Enables the torch on camera startup
|
||||
* If provided, should be a boolean.
|
||||
*/
|
||||
public static final String TORCH_ENABLED = "TORCH_ENABLED";
|
||||
|
||||
/**
|
||||
* @see com.google.zxing.DecodeHintType#CHARACTER_SET
|
||||
*/
|
||||
@@ -108,6 +115,21 @@ public final class Intents {
|
||||
*/
|
||||
public static final String TIMEOUT = "TIMEOUT";
|
||||
|
||||
/**
|
||||
* Set the time to finish the scan screen.
|
||||
*/
|
||||
public static final String MISSING_CAMERA_PERMISSION = "MISSING_CAMERA_PERMISSION";
|
||||
|
||||
/**
|
||||
* Set the time to finish the scan screen.
|
||||
*/
|
||||
public static final String SHOW_MISSING_CAMERA_PERMISSION_DIALOG = "SHOW_MISSING_CAMERA_PERMISSION_DIALOG";
|
||||
|
||||
/**
|
||||
* Set the time to finish the scan screen.
|
||||
*/
|
||||
public static final String MISSING_CAMERA_PERMISSION_DIALOG_MESSAGE = "MISSING_CAMERA_PERMISSION_DIALOG_MESSAGE";
|
||||
|
||||
/**
|
||||
* Whether or not the orientation should be locked when the activity is first started.
|
||||
* Defaults to true.
|
||||
@@ -172,7 +194,7 @@ public final class Intents {
|
||||
public static final String RESULT_BYTE_SEGMENTS_PREFIX = "SCAN_RESULT_BYTE_SEGMENTS_";
|
||||
|
||||
/**
|
||||
* Call {@link android.content.Intent#getStringExtra(String)} with {@link #SCAN_RESULT_IMAGE_PATH}
|
||||
* Call {@link android.content.Intent#getStringExtra(String)} with {@link #RESULT_BARCODE_IMAGE_PATH}
|
||||
* to get a {@code String} path to a cropped and compressed png file of the barcode's image
|
||||
* as it was displayed. Only available if
|
||||
* {@link com.google.zxing.integration.android.IntentIntegrator#setBarcodeImageEnabled(boolean)}
|
||||
@@ -180,6 +202,26 @@ public final class Intents {
|
||||
*/
|
||||
public static final String RESULT_BARCODE_IMAGE_PATH = "SCAN_RESULT_IMAGE_PATH";
|
||||
|
||||
/**
|
||||
* Define the scan type.
|
||||
*/
|
||||
public static final String SCAN_TYPE = "SCAN_TYPE";
|
||||
|
||||
/**
|
||||
* Scan normal barcodes white on black
|
||||
*/
|
||||
public static final int NORMAL_SCAN = 0;
|
||||
|
||||
/**
|
||||
* The scan should be inverted. White becomes black, black becomes white.
|
||||
*/
|
||||
public static final int INVERTED_SCAN = 1;
|
||||
|
||||
/**
|
||||
* Scan alternating inverted and normal barcodes.
|
||||
*/
|
||||
public static final int MIXED_SCAN = 2;
|
||||
|
||||
private Scan() {
|
||||
}
|
||||
}
|
||||
|
||||
-1
@@ -83,5 +83,4 @@ public final class OpenCameraInterface {
|
||||
return Camera.open(cameraId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+120
-39
@@ -22,8 +22,6 @@ import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.google.zxing.client.android.Intents;
|
||||
import com.journeyapps.barcodescanner.CaptureActivity;
|
||||
@@ -36,45 +34,67 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sean Owen
|
||||
* @author Fred Lin
|
||||
* @author Isaac Potoczny-Jones
|
||||
* @author Brad Drehmer
|
||||
* @author gcstang
|
||||
* @deprecated Use ScanOptions and ScanContract instead.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class IntentIntegrator {
|
||||
|
||||
public static final int REQUEST_CODE = 0x0000c0de; // Only use bottom 16 bits
|
||||
|
||||
private static final String TAG = IntentIntegrator.class.getSimpleName();
|
||||
|
||||
|
||||
// supported barcode formats
|
||||
public static final Collection<String> PRODUCT_CODE_TYPES = list("UPC_A", "UPC_E", "EAN_8", "EAN_13", "RSS_14");
|
||||
|
||||
// Product Codes
|
||||
public static final String UPC_A = "UPC_A";
|
||||
public static final String UPC_E = "UPC_E";
|
||||
public static final String EAN_8 = "EAN_8";
|
||||
public static final String EAN_13 = "EAN_13";
|
||||
public static final String RSS_14 = "RSS_14";
|
||||
|
||||
// Other 1D
|
||||
public static final String CODE_39 = "CODE_39";
|
||||
public static final String CODE_93 = "CODE_93";
|
||||
public static final String CODE_128 = "CODE_128";
|
||||
public static final String ITF = "ITF";
|
||||
|
||||
public static final String RSS_EXPANDED = "RSS_EXPANDED";
|
||||
|
||||
// 2D
|
||||
public static final String QR_CODE = "QR_CODE";
|
||||
public static final String DATA_MATRIX = "DATA_MATRIX";
|
||||
public static final String PDF_417 = "PDF_417";
|
||||
|
||||
|
||||
public static final Collection<String> PRODUCT_CODE_TYPES = list(UPC_A, UPC_E, EAN_8, EAN_13, RSS_14);
|
||||
public static final Collection<String> ONE_D_CODE_TYPES =
|
||||
list("UPC_A", "UPC_E", "EAN_8", "EAN_13", "CODE_39", "CODE_93", "CODE_128",
|
||||
"ITF", "RSS_14", "RSS_EXPANDED");
|
||||
public static final Collection<String> QR_CODE_TYPES = Collections.singleton("QR_CODE");
|
||||
public static final Collection<String> DATA_MATRIX_TYPES = Collections.singleton("DATA_MATRIX");
|
||||
list(UPC_A, UPC_E, EAN_8, EAN_13, RSS_14, CODE_39, CODE_93, CODE_128,
|
||||
ITF, RSS_14, RSS_EXPANDED);
|
||||
|
||||
public static final Collection<String> ALL_CODE_TYPES = null;
|
||||
|
||||
private final Activity activity;
|
||||
private android.app.Fragment fragment;
|
||||
private android.support.v4.app.Fragment supportFragment;
|
||||
private androidx.fragment.app.Fragment supportFragment;
|
||||
|
||||
private final Map<String, Object> moreExtras = new HashMap<String, Object>(3);
|
||||
private final Map<String, Object> moreExtras = new HashMap<>(3);
|
||||
|
||||
private Collection<String> desiredBarcodeFormats;
|
||||
|
||||
private Class<?> captureActivity;
|
||||
|
||||
private int requestCode = REQUEST_CODE;
|
||||
|
||||
protected Class<?> getDefaultCaptureActivity() {
|
||||
return CaptureActivity.class;
|
||||
}
|
||||
/**
|
||||
* @param activity {@link Activity} invoking the integration
|
||||
*/
|
||||
|
||||
public IntentIntegrator(Activity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
@@ -97,12 +117,27 @@ public class IntentIntegrator {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the request code that is used for the Intent. If it is changed, it is the caller's
|
||||
* responsibility to check the request code from the result intent.
|
||||
*
|
||||
* @param requestCode the new request code
|
||||
* @return this
|
||||
*/
|
||||
public IntentIntegrator setRequestCode(int requestCode) {
|
||||
if (requestCode <= 0 || requestCode > 0x0000ffff) {
|
||||
throw new IllegalArgumentException("requestCode out of range");
|
||||
}
|
||||
this.requestCode = requestCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fragment {@link Fragment} invoking the integration.
|
||||
* {@link #startActivityForResult(Intent, int)} will be called on the {@link Fragment} instead
|
||||
* of an {@link Activity}
|
||||
*/
|
||||
public static IntentIntegrator forSupportFragment(android.support.v4.app.Fragment fragment) {
|
||||
public static IntentIntegrator forSupportFragment(androidx.fragment.app.Fragment fragment) {
|
||||
IntentIntegrator integrator = new IntentIntegrator(fragment.getActivity());
|
||||
integrator.supportFragment = fragment;
|
||||
return integrator;
|
||||
@@ -164,6 +199,18 @@ public class IntentIntegrator {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to true to enable initial torch
|
||||
*
|
||||
* @param enabled true to enable initial torch
|
||||
* @return this
|
||||
*/
|
||||
public IntentIntegrator setTorchEnabled(boolean enabled) {
|
||||
addExtra(Intents.Scan.TORCH_ENABLED, enabled);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set to false to disable beep on scan.
|
||||
*
|
||||
@@ -197,16 +244,28 @@ public class IntentIntegrator {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the desired barcode formats to scan.
|
||||
*
|
||||
* @param desiredBarcodeFormats names of {@code BarcodeFormat}s to scan for
|
||||
* @return this
|
||||
*/
|
||||
public IntentIntegrator setDesiredBarcodeFormats(String... desiredBarcodeFormats) {
|
||||
this.desiredBarcodeFormats = Arrays.asList(desiredBarcodeFormats);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates a scan for all known barcode types with the default camera.
|
||||
*/
|
||||
public final void initiateScan() {
|
||||
startActivityForResult(createScanIntent(), REQUEST_CODE);
|
||||
startActivityForResult(createScanIntent(), requestCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates a scan for all known barcode types with the default camera.
|
||||
* And starts a timer to finish on timeout
|
||||
*
|
||||
* @return Activity.RESULT_CANCELED and true on parameter TIMEOUT.
|
||||
*/
|
||||
public IntentIntegrator setTimeout(long timeout) {
|
||||
@@ -265,9 +324,7 @@ public class IntentIntegrator {
|
||||
*/
|
||||
protected void startActivityForResult(Intent intent, int code) {
|
||||
if (fragment != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
fragment.startActivityForResult(intent, code);
|
||||
}
|
||||
fragment.startActivityForResult(intent, code);
|
||||
} else if (supportFragment != null) {
|
||||
supportFragment.startActivityForResult(intent, code);
|
||||
} else {
|
||||
@@ -275,12 +332,9 @@ public class IntentIntegrator {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void startActivity(Intent intent) {
|
||||
if (fragment != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
fragment.startActivity(intent);
|
||||
}
|
||||
fragment.startActivity(intent);
|
||||
} else if (supportFragment != null) {
|
||||
supportFragment.startActivity(intent);
|
||||
} else {
|
||||
@@ -291,6 +345,8 @@ public class IntentIntegrator {
|
||||
/**
|
||||
* <p>Call this from your {@link Activity}'s
|
||||
* {@link Activity#onActivityResult(int, int, Intent)} method.</p>
|
||||
* <p>
|
||||
* This checks that the requestCode is equal to the default REQUEST_CODE.
|
||||
*
|
||||
* @param requestCode request code from {@code onActivityResult()}
|
||||
* @param resultCode result code from {@code onActivityResult()}
|
||||
@@ -298,29 +354,43 @@ public class IntentIntegrator {
|
||||
* @return null if the event handled here was not related to this class, or
|
||||
* else an {@link IntentResult} containing the result of the scan. If the user cancelled scanning,
|
||||
* the fields will be null.
|
||||
* @deprecated Not compatible with setRequestCode(). Use parseActivityResult(resultCode, intent) instead.
|
||||
*/
|
||||
public static IntentResult parseActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
if (requestCode == REQUEST_CODE) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
String contents = intent.getStringExtra(Intents.Scan.RESULT);
|
||||
String formatName = intent.getStringExtra(Intents.Scan.RESULT_FORMAT);
|
||||
byte[] rawBytes = intent.getByteArrayExtra(Intents.Scan.RESULT_BYTES);
|
||||
int intentOrientation = intent.getIntExtra(Intents.Scan.RESULT_ORIENTATION, Integer.MIN_VALUE);
|
||||
Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation;
|
||||
String errorCorrectionLevel = intent.getStringExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL);
|
||||
String barcodeImagePath = intent.getStringExtra(Intents.Scan.RESULT_BARCODE_IMAGE_PATH);
|
||||
return new IntentResult(contents,
|
||||
formatName,
|
||||
rawBytes,
|
||||
orientation,
|
||||
errorCorrectionLevel,
|
||||
barcodeImagePath);
|
||||
}
|
||||
return new IntentResult();
|
||||
return parseActivityResult(resultCode, intent);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse activity result, without checking the request code.
|
||||
*
|
||||
* @param resultCode result code from {@code onActivityResult()}
|
||||
* @param intent {@link Intent} from {@code onActivityResult()}
|
||||
* @return an {@link IntentResult} containing the result of the scan. If the user cancelled scanning,
|
||||
* the fields will be null.
|
||||
*/
|
||||
public static IntentResult parseActivityResult(int resultCode, Intent intent) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
String contents = intent.getStringExtra(Intents.Scan.RESULT);
|
||||
String formatName = intent.getStringExtra(Intents.Scan.RESULT_FORMAT);
|
||||
byte[] rawBytes = intent.getByteArrayExtra(Intents.Scan.RESULT_BYTES);
|
||||
int intentOrientation = intent.getIntExtra(Intents.Scan.RESULT_ORIENTATION, Integer.MIN_VALUE);
|
||||
Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation;
|
||||
String errorCorrectionLevel = intent.getStringExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL);
|
||||
String barcodeImagePath = intent.getStringExtra(Intents.Scan.RESULT_BARCODE_IMAGE_PATH);
|
||||
return new IntentResult(contents,
|
||||
formatName,
|
||||
rawBytes,
|
||||
orientation,
|
||||
errorCorrectionLevel,
|
||||
barcodeImagePath,
|
||||
intent);
|
||||
}
|
||||
return new IntentResult(intent);
|
||||
}
|
||||
|
||||
private static List<String> list(String... values) {
|
||||
return Collections.unmodifiableList(Arrays.asList(values));
|
||||
}
|
||||
@@ -342,10 +412,21 @@ public class IntentIntegrator {
|
||||
intent.putExtra(key, (Float) value);
|
||||
} else if (value instanceof Bundle) {
|
||||
intent.putExtra(key, (Bundle) value);
|
||||
} else if (value instanceof int[]) {
|
||||
intent.putExtra(key, (int[]) value);
|
||||
} else if (value instanceof long[]) {
|
||||
intent.putExtra(key, (long[]) value);
|
||||
} else if (value instanceof boolean[]) {
|
||||
intent.putExtra(key, (boolean[]) value);
|
||||
} else if (value instanceof double[]) {
|
||||
intent.putExtra(key, (double[]) value);
|
||||
} else if (value instanceof float[]) {
|
||||
intent.putExtra(key, (float[]) value);
|
||||
} else if (value instanceof String[]) {
|
||||
intent.putExtra(key, (String[]) value);
|
||||
} else {
|
||||
intent.putExtra(key, value.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.google.zxing.integration.android;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* <p>Encapsulates the result of a barcode scan invoked through {@link IntentIntegrator}.</p>
|
||||
*
|
||||
@@ -29,9 +31,14 @@ public final class IntentResult {
|
||||
private final Integer orientation;
|
||||
private final String errorCorrectionLevel;
|
||||
private final String barcodeImagePath;
|
||||
private final Intent originalIntent;
|
||||
|
||||
IntentResult() {
|
||||
this(null, null, null, null, null, null);
|
||||
this(null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
IntentResult(Intent intent) {
|
||||
this(null, null, null, null, null, null, intent);
|
||||
}
|
||||
|
||||
IntentResult(String contents,
|
||||
@@ -39,13 +46,15 @@ public final class IntentResult {
|
||||
byte[] rawBytes,
|
||||
Integer orientation,
|
||||
String errorCorrectionLevel,
|
||||
String barcodeImagePath) {
|
||||
String barcodeImagePath,
|
||||
Intent originalIntent) {
|
||||
this.contents = contents;
|
||||
this.formatName = formatName;
|
||||
this.rawBytes = rawBytes;
|
||||
this.orientation = orientation;
|
||||
this.errorCorrectionLevel = errorCorrectionLevel;
|
||||
this.barcodeImagePath = barcodeImagePath;
|
||||
this.originalIntent = originalIntent;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,17 +99,22 @@ public final class IntentResult {
|
||||
return barcodeImagePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder dialogText = new StringBuilder(120);
|
||||
dialogText.append("Format: ").append(formatName).append('\n');
|
||||
dialogText.append("Contents: ").append(contents).append('\n');
|
||||
int rawBytesLength = rawBytes == null ? 0 : rawBytes.length;
|
||||
dialogText.append("Raw bytes: (").append(rawBytesLength).append(" bytes)\n");
|
||||
dialogText.append("Orientation: ").append(orientation).append('\n');
|
||||
dialogText.append("EC level: ").append(errorCorrectionLevel).append('\n');
|
||||
dialogText.append("Barcode image: ").append(barcodeImagePath).append('\n');
|
||||
return dialogText.toString();
|
||||
/**
|
||||
* @return the original intent
|
||||
*/
|
||||
public Intent getOriginalIntent() {
|
||||
return originalIntent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
int rawBytesLength = rawBytes == null ? 0 : rawBytes.length;
|
||||
return "Format: " + formatName + '\n' +
|
||||
"Contents: " + contents + '\n' +
|
||||
"Raw bytes: (" + rawBytesLength + " bytes)\n" +
|
||||
"Orientation: " + orientation + '\n' +
|
||||
"EC level: " + errorCorrectionLevel + '\n' +
|
||||
"Barcode image: " + barcodeImagePath + '\n' +
|
||||
"Original intent: " + originalIntent + '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,10 @@ public interface BarcodeCallback {
|
||||
*
|
||||
* Do not depend on this being called at any specific point in the decode cycle.
|
||||
*
|
||||
* This is a default method and can be omitted by the implementing class.
|
||||
*
|
||||
* @param resultPoints points potentially identifying a barcode
|
||||
*/
|
||||
void possibleResultPoints(List<ResultPoint> resultPoints);
|
||||
default void possibleResultPoints(List<ResultPoint> resultPoints) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.graphics.Bitmap;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.MultiFormatWriter;
|
||||
import com.google.zxing.Writer;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
@@ -20,13 +19,21 @@ import java.util.Map;
|
||||
* Licensed under the Apache License, Version 2.0.
|
||||
*/
|
||||
public class BarcodeEncoder {
|
||||
private static final int WHITE = 0xFFFFFFFF;
|
||||
private static final int BLACK = 0xFF000000;
|
||||
private int bgColor = 0xFFFFFFFF;
|
||||
private int fgColor = 0xFF000000;
|
||||
|
||||
|
||||
public BarcodeEncoder() {
|
||||
}
|
||||
|
||||
public void setBackgroundColor(int bgColor) {
|
||||
this.bgColor = bgColor;
|
||||
}
|
||||
|
||||
public void setForegroundColor(int fgColor) {
|
||||
this.fgColor = fgColor;
|
||||
}
|
||||
|
||||
public Bitmap createBitmap(BitMatrix matrix) {
|
||||
int width = matrix.getWidth();
|
||||
int height = matrix.getHeight();
|
||||
@@ -34,7 +41,7 @@ public class BarcodeEncoder {
|
||||
for (int y = 0; y < height; y++) {
|
||||
int offset = y * width;
|
||||
for (int x = 0; x < width; x++) {
|
||||
pixels[offset + x] = matrix.get(x, y) ? BLACK : WHITE;
|
||||
pixels[offset + x] = matrix.get(x, y) ? fgColor : bgColor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,8 +78,4 @@ public class BarcodeEncoder {
|
||||
public Bitmap encodeBitmap(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType, ?> hints) throws WriterException {
|
||||
return createBitmap(encode(contents, format, width, height, hints));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultMetadataType;
|
||||
import com.google.zxing.ResultPoint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -54,7 +58,14 @@ public class BarcodeResult {
|
||||
* @see #getBitmapWithResultPoints(int)
|
||||
*/
|
||||
public Bitmap getBitmap() {
|
||||
return sourceData.getBitmap(mScaleFactor);
|
||||
return sourceData.getBitmap(null, mScaleFactor);
|
||||
}
|
||||
|
||||
public List<ResultPoint> getTransformedResultPoints() {
|
||||
if (this.mResult.getResultPoints() == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return transformResultPoints(Arrays.asList(this.mResult.getResultPoints()), this.sourceData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,23 +75,23 @@ public class BarcodeResult {
|
||||
public Bitmap getBitmapWithResultPoints(int color) {
|
||||
Bitmap bitmap = getBitmap();
|
||||
Bitmap barcode = bitmap;
|
||||
ResultPoint[] points = mResult.getResultPoints();
|
||||
List<ResultPoint> points = getTransformedResultPoints();
|
||||
|
||||
if (points != null && points.length > 0 && bitmap != null) {
|
||||
if (!points.isEmpty() && bitmap != null) {
|
||||
barcode = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(barcode);
|
||||
canvas.drawBitmap(bitmap, 0, 0, null);
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(color);
|
||||
if (points.length == 2) {
|
||||
if (points.size() == 2) {
|
||||
paint.setStrokeWidth(PREVIEW_LINE_WIDTH);
|
||||
drawLine(canvas, paint, points[0], points[1], mScaleFactor);
|
||||
} else if (points.length == 4 &&
|
||||
drawLine(canvas, paint, points.get(0), points.get(1), mScaleFactor);
|
||||
} else if (points.size() == 4 &&
|
||||
(mResult.getBarcodeFormat() == BarcodeFormat.UPC_A ||
|
||||
mResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
|
||||
// Hacky special case -- draw two lines, for the barcode and metadata
|
||||
drawLine(canvas, paint, points[0], points[1], mScaleFactor);
|
||||
drawLine(canvas, paint, points[2], points[3], mScaleFactor);
|
||||
drawLine(canvas, paint, points.get(0), points.get(1), mScaleFactor);
|
||||
drawLine(canvas, paint, points.get(2), points.get(3), mScaleFactor);
|
||||
} else {
|
||||
paint.setStrokeWidth(PREVIEW_DOT_WIDTH);
|
||||
for (ResultPoint point : points) {
|
||||
@@ -153,4 +164,13 @@ public class BarcodeResult {
|
||||
public String toString() {
|
||||
return mResult.getText();
|
||||
}
|
||||
|
||||
|
||||
public static List<ResultPoint> transformResultPoints(List<ResultPoint> resultPoints, SourceData sourceData) {
|
||||
List<ResultPoint> scaledPoints = new ArrayList<>(resultPoints.size());
|
||||
for (ResultPoint point : resultPoints) {
|
||||
scaledPoints.add(sourceData.translateResultPoint(point));
|
||||
}
|
||||
return scaledPoints;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.journeyapps.barcodescanner;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.AttributeSet;
|
||||
@@ -62,6 +60,7 @@ public class BarcodeView extends CameraPreview {
|
||||
// Failed. Next preview is automatically tried.
|
||||
return true;
|
||||
} else if (message.what == R.id.zxing_possible_result_points) {
|
||||
//noinspection unchecked
|
||||
List<ResultPoint> resultPoints = (List<ResultPoint>) message.obj;
|
||||
if (callback != null && decodeMode != DecodeMode.NONE) {
|
||||
callback.possibleResultPoints(resultPoints);
|
||||
@@ -75,26 +74,24 @@ public class BarcodeView extends CameraPreview {
|
||||
|
||||
public BarcodeView(Context context) {
|
||||
super(context);
|
||||
initialize(context, null);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public BarcodeView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initialize(context, attrs);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public BarcodeView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
initialize(context, attrs);
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
||||
private void initialize(Context context, AttributeSet attrs) {
|
||||
private void initialize() {
|
||||
decoderFactory = new DefaultDecoderFactory();
|
||||
resultHandler = new Handler(resultCallback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the DecoderFactory to use. Use this to specify the formats to decode.
|
||||
*
|
||||
@@ -145,7 +142,6 @@ public class BarcodeView extends CameraPreview {
|
||||
startDecoderThread();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Continuously decode barcodes. The same barcode may be returned multiple times per second.
|
||||
*
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.view.WindowManager;
|
||||
|
||||
import com.google.zxing.client.android.R;
|
||||
import com.journeyapps.barcodescanner.camera.CameraInstance;
|
||||
import com.journeyapps.barcodescanner.camera.CameraParametersCallback;
|
||||
import com.journeyapps.barcodescanner.camera.CameraSettings;
|
||||
import com.journeyapps.barcodescanner.camera.CameraSurface;
|
||||
import com.journeyapps.barcodescanner.camera.CenterCropStrategy;
|
||||
@@ -79,6 +80,11 @@ public class CameraPreview extends ViewGroup {
|
||||
* @param error the error
|
||||
*/
|
||||
void cameraError(Exception error);
|
||||
|
||||
/**
|
||||
* The camera has been closed.
|
||||
*/
|
||||
void cameraClosed();
|
||||
}
|
||||
|
||||
private static final String TAG = CameraPreview.class.getSimpleName();
|
||||
@@ -191,6 +197,8 @@ public class CameraPreview extends ViewGroup {
|
||||
@Override
|
||||
public boolean handleMessage(Message message) {
|
||||
if (message.what == R.id.zxing_prewiew_size_ready) {
|
||||
// At this point, we have the camera preview size, and should have containerSize and
|
||||
// surfaceRect.
|
||||
previewSized((Size) message.obj);
|
||||
return true;
|
||||
} else if (message.what == R.id.zxing_camera_error) {
|
||||
@@ -201,6 +209,8 @@ public class CameraPreview extends ViewGroup {
|
||||
pause();
|
||||
fireState.cameraError(error);
|
||||
}
|
||||
} else if (message.what == R.id.zxing_camera_closed) {
|
||||
fireState.cameraClosed();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -210,12 +220,7 @@ public class CameraPreview extends ViewGroup {
|
||||
@Override
|
||||
public void onRotationChanged(int rotation) {
|
||||
// Make sure this is run on the main thread.
|
||||
stateHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
rotationChanged();
|
||||
}
|
||||
}, ROTATION_LISTENER_DELAY_MS);
|
||||
stateHandler.postDelayed(() -> rotationChanged(), ROTATION_LISTENER_DELAY_MS);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -234,7 +239,6 @@ public class CameraPreview extends ViewGroup {
|
||||
initialize(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
|
||||
private void initialize(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
if (getBackground() == null) {
|
||||
// Default to SurfaceView colour, so that there are less changes.
|
||||
@@ -262,7 +266,7 @@ public class CameraPreview extends ViewGroup {
|
||||
*
|
||||
* @param attrs the attributes
|
||||
*/
|
||||
protected void initializeAttributes(AttributeSet attrs) {
|
||||
public void initializeAttributes(AttributeSet attrs) {
|
||||
TypedArray styledAttributes = getContext().obtainStyledAttributes(attrs, R.styleable.zxing_camera_preview);
|
||||
|
||||
int framingRectWidth = (int) styledAttributes.getDimension(R.styleable.zxing_camera_preview_zxing_framing_rect_width, -1);
|
||||
@@ -276,11 +280,11 @@ public class CameraPreview extends ViewGroup {
|
||||
|
||||
// See zxing_attrs.xml for the enum values
|
||||
int scalingStrategyNumber = styledAttributes.getInteger(R.styleable.zxing_camera_preview_zxing_preview_scaling_strategy, -1);
|
||||
if(scalingStrategyNumber == 1) {
|
||||
if (scalingStrategyNumber == 1) {
|
||||
previewScalingStrategy = new CenterCropStrategy();
|
||||
} else if(scalingStrategyNumber == 2) {
|
||||
} else if (scalingStrategyNumber == 2) {
|
||||
previewScalingStrategy = new FitCenterStrategy();
|
||||
} else if(scalingStrategyNumber == 3) {
|
||||
} else if (scalingStrategyNumber == 3) {
|
||||
previewScalingStrategy = new FitXYStrategy();
|
||||
}
|
||||
|
||||
@@ -289,22 +293,19 @@ public class CameraPreview extends ViewGroup {
|
||||
|
||||
private void rotationChanged() {
|
||||
// Confirm that it did actually change
|
||||
if(isActive() && getDisplayRotation() != openedOrientation) {
|
||||
if (isActive() && getDisplayRotation() != openedOrientation) {
|
||||
pause();
|
||||
resume();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupSurfaceView() {
|
||||
if(useTextureView && Build.VERSION.SDK_INT >= 14) {
|
||||
if (useTextureView) {
|
||||
textureView = new TextureView(getContext());
|
||||
textureView.setSurfaceTextureListener(surfaceTextureListener());
|
||||
addView(textureView);
|
||||
} else {
|
||||
surfaceView = new SurfaceView(getContext());
|
||||
if (Build.VERSION.SDK_INT < 11) {
|
||||
surfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
||||
}
|
||||
surfaceView.getHolder().addCallback(surfaceCallback);
|
||||
addView(surfaceView);
|
||||
}
|
||||
@@ -348,6 +349,13 @@ public class CameraPreview extends ViewGroup {
|
||||
listener.cameraError(error);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cameraClosed() {
|
||||
for (StateListener listener : stateListeners) {
|
||||
listener.cameraClosed();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void calculateFrames() {
|
||||
@@ -364,7 +372,13 @@ public class CameraPreview extends ViewGroup {
|
||||
int width = containerSize.width;
|
||||
int height = containerSize.height;
|
||||
|
||||
surfaceRect = displayConfiguration.scalePreview(previewSize);
|
||||
Rect scaledPreview = displayConfiguration.scalePreview(previewSize);
|
||||
if (scaledPreview.width() <= 0 || scaledPreview.height() <= 0) {
|
||||
// Something is not ready yet - we can't start the preview.
|
||||
return;
|
||||
}
|
||||
|
||||
surfaceRect = scaledPreview;
|
||||
|
||||
Rect container = new Rect(0, 0, width, height);
|
||||
framingRect = calculateFramingRect(container, surfaceRect);
|
||||
@@ -376,7 +390,7 @@ public class CameraPreview extends ViewGroup {
|
||||
frameInPreview.right * previewWidth / surfaceRect.width(),
|
||||
frameInPreview.bottom * previewHeight / surfaceRect.height());
|
||||
|
||||
if (previewFramingRect.width() <= 0 || previewFramingRect.height() <= 0) {
|
||||
if (previewFramingRect == null || previewFramingRect.width() <= 0 || previewFramingRect.height() <= 0) {
|
||||
previewFramingRect = null;
|
||||
framingRect = null;
|
||||
Log.w(TAG, "Preview frame is too small");
|
||||
@@ -397,6 +411,18 @@ public class CameraPreview extends ViewGroup {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the settings for Camera.
|
||||
* Must be called after {@link #resume()}.
|
||||
*
|
||||
* @param callback {@link CameraParametersCallback}
|
||||
*/
|
||||
public void changeCameraParameters(CameraParametersCallback callback) {
|
||||
if (cameraInstance != null) {
|
||||
cameraInstance.changeCameraParameters(callback);
|
||||
}
|
||||
}
|
||||
|
||||
private void containerSized(Size containerSize) {
|
||||
this.containerSize = containerSize;
|
||||
if (cameraInstance != null) {
|
||||
@@ -405,7 +431,7 @@ public class CameraPreview extends ViewGroup {
|
||||
displayConfiguration.setPreviewScalingStrategy(getPreviewScalingStrategy());
|
||||
cameraInstance.setDisplayConfiguration(displayConfiguration);
|
||||
cameraInstance.configureCamera();
|
||||
if(torchOn) {
|
||||
if (torchOn) {
|
||||
cameraInstance.setTorch(torchOn);
|
||||
}
|
||||
}
|
||||
@@ -425,14 +451,14 @@ public class CameraPreview extends ViewGroup {
|
||||
* Override this to specify a different preview scaling strategy.
|
||||
*/
|
||||
public PreviewScalingStrategy getPreviewScalingStrategy() {
|
||||
if(previewScalingStrategy != null) {
|
||||
if (previewScalingStrategy != null) {
|
||||
return previewScalingStrategy;
|
||||
}
|
||||
|
||||
// If we are using SurfaceTexture, it is safe to use centerCrop.
|
||||
// For SurfaceView, it's better to use fitCenter, otherwise the preview may overlap to
|
||||
// other views.
|
||||
if(textureView != null) {
|
||||
if (textureView != null) {
|
||||
return new CenterCropStrategy();
|
||||
} else {
|
||||
return new FitCenterStrategy();
|
||||
@@ -495,8 +521,8 @@ public class CameraPreview extends ViewGroup {
|
||||
if (currentSurfaceSize != null && previewSize != null && surfaceRect != null) {
|
||||
if (surfaceView != null && currentSurfaceSize.equals(new Size(surfaceRect.width(), surfaceRect.height()))) {
|
||||
startCameraPreview(new CameraSurface(surfaceView.getHolder()));
|
||||
} else if(textureView != null && Build.VERSION.SDK_INT >= 14 && textureView.getSurfaceTexture() != null) {
|
||||
if(previewSize != null) {
|
||||
} else if (textureView != null && textureView.getSurfaceTexture() != null) {
|
||||
if (previewSize != null) {
|
||||
Matrix transform = calculateTextureTransform(new Size(textureView.getWidth(), textureView.getHeight()), previewSize);
|
||||
textureView.setTransform(transform);
|
||||
}
|
||||
@@ -513,7 +539,7 @@ public class CameraPreview extends ViewGroup {
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
containerSized(new Size(r - l, b - t));
|
||||
|
||||
if(surfaceView != null) {
|
||||
if (surfaceView != null) {
|
||||
if (surfaceRect == null) {
|
||||
// Match the container, to reduce the risk of issues. The preview should never be drawn
|
||||
// while the surface has this size.
|
||||
@@ -521,7 +547,7 @@ public class CameraPreview extends ViewGroup {
|
||||
} else {
|
||||
surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
|
||||
}
|
||||
} else if(textureView != null && Build.VERSION.SDK_INT >= 14) {
|
||||
} else if (textureView != null) {
|
||||
textureView.layout(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
}
|
||||
@@ -550,6 +576,10 @@ public class CameraPreview extends ViewGroup {
|
||||
return previewFramingRect;
|
||||
}
|
||||
|
||||
public Size getPreviewSize() {
|
||||
return previewSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the CameraSettings currently in use
|
||||
*/
|
||||
@@ -587,11 +617,15 @@ public class CameraPreview extends ViewGroup {
|
||||
// The activity was paused but not stopped, so the surface still exists. Therefore
|
||||
// surfaceCreated() won't be called, so init the camera here.
|
||||
startPreviewIfReady();
|
||||
} else if(surfaceView != null) {
|
||||
} else if (surfaceView != null) {
|
||||
// Install the callback and wait for surfaceCreated() to init the camera.
|
||||
surfaceView.getHolder().addCallback(surfaceCallback);
|
||||
} else if(textureView != null && Build.VERSION.SDK_INT >= 14) {
|
||||
textureView.setSurfaceTextureListener(surfaceTextureListener());
|
||||
} else if (textureView != null) {
|
||||
if (textureView.isAvailable()) {
|
||||
surfaceTextureListener().onSurfaceTextureAvailable(textureView.getSurfaceTexture(), textureView.getWidth(), textureView.getHeight());
|
||||
} else {
|
||||
textureView.setSurfaceTextureListener(surfaceTextureListener());
|
||||
}
|
||||
}
|
||||
|
||||
// To trigger surfaceSized again
|
||||
@@ -599,7 +633,6 @@ public class CameraPreview extends ViewGroup {
|
||||
rotationListener.listen(getContext(), rotationCallback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pause scanning and the camera preview. Typically this should be called from the Activity's
|
||||
* onPause() method.
|
||||
@@ -616,12 +649,14 @@ public class CameraPreview extends ViewGroup {
|
||||
cameraInstance.close();
|
||||
cameraInstance = null;
|
||||
previewActive = false;
|
||||
} else {
|
||||
stateHandler.sendEmptyMessage(R.id.zxing_camera_closed);
|
||||
}
|
||||
if (currentSurfaceSize == null && surfaceView != null) {
|
||||
SurfaceHolder surfaceHolder = surfaceView.getHolder();
|
||||
surfaceHolder.removeCallback(surfaceCallback);
|
||||
}
|
||||
if(currentSurfaceSize == null && textureView != null && Build.VERSION.SDK_INT >= 14) {
|
||||
if (currentSurfaceSize == null && textureView != null) {
|
||||
textureView.setSurfaceTextureListener(null);
|
||||
}
|
||||
|
||||
@@ -633,6 +668,28 @@ public class CameraPreview extends ViewGroup {
|
||||
fireState.previewStopped();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause scanning and preview; waiting for the Camera to be closed.
|
||||
*
|
||||
* This blocks the main thread.
|
||||
*/
|
||||
public void pauseAndWait() {
|
||||
CameraInstance instance = getCameraInstance();
|
||||
pause();
|
||||
long startTime = System.nanoTime();
|
||||
while(instance != null && !instance.isCameraClosed()) {
|
||||
if (System.nanoTime() - startTime > 2000000000) {
|
||||
// Don't wait for longer than 2 seconds
|
||||
break;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Size getFramingRectSize() {
|
||||
return framingRectSize;
|
||||
}
|
||||
@@ -657,7 +714,7 @@ public class CameraPreview extends ViewGroup {
|
||||
* @param marginFraction the fraction
|
||||
*/
|
||||
public void setMarginFraction(double marginFraction) {
|
||||
if(marginFraction >= 0.5d) {
|
||||
if (marginFraction >= 0.5d) {
|
||||
throw new IllegalArgumentException("The margin fraction must be less than 0.5");
|
||||
}
|
||||
this.marginFraction = marginFraction;
|
||||
@@ -720,7 +777,6 @@ public class CameraPreview extends ViewGroup {
|
||||
return cameraInstance;
|
||||
}
|
||||
|
||||
|
||||
private void startCameraPreview(CameraSurface surface) {
|
||||
if (!previewActive && cameraInstance != null) {
|
||||
Log.i(TAG, "Starting preview");
|
||||
@@ -763,7 +819,6 @@ public class CameraPreview extends ViewGroup {
|
||||
return previewActive;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate framing rectangle, relative to the preview frame.
|
||||
*
|
||||
@@ -780,7 +835,7 @@ public class CameraPreview extends ViewGroup {
|
||||
Rect intersection = new Rect(container);
|
||||
boolean intersects = intersection.intersect(surface);
|
||||
|
||||
if(framingRectSize != null) {
|
||||
if (framingRectSize != null) {
|
||||
// Specific size is specified. Make sure it's not larger than the container or surface.
|
||||
int horizontalMargin = Math.max(0, (intersection.width() - framingRectSize.width) / 2);
|
||||
int verticalMargin = Math.max(0, (intersection.height() - framingRectSize.height) / 2);
|
||||
@@ -809,7 +864,7 @@ public class CameraPreview extends ViewGroup {
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
if(!(state instanceof Bundle)) {
|
||||
if (!(state instanceof Bundle)) {
|
||||
super.onRestoreInstanceState(state);
|
||||
return;
|
||||
}
|
||||
@@ -819,4 +874,12 @@ public class CameraPreview extends ViewGroup {
|
||||
boolean torch = myState.getBoolean("torch");
|
||||
setTorch(torch);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if the camera has been closed in a background thread.
|
||||
*/
|
||||
public boolean isCameraClosed() {
|
||||
return cameraInstance == null || cameraInstance.isCameraClosed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.journeyapps.barcodescanner;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.google.zxing.client.android.R;
|
||||
@@ -59,11 +60,10 @@ public class CaptureActivity extends Activity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
|
||||
capture.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
return barcodeScannerView.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.Manifest;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -13,21 +12,21 @@ import android.graphics.Bitmap;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.Surface;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.google.zxing.ResultMetadataType;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.client.android.BeepManager;
|
||||
import com.google.zxing.client.android.InactivityTimer;
|
||||
import com.google.zxing.client.android.Intents;
|
||||
import com.google.zxing.client.android.R;
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -62,30 +61,25 @@ public class CaptureManager {
|
||||
private static final String SAVED_ORIENTATION_LOCK = "SAVED_ORIENTATION_LOCK";
|
||||
private boolean returnBarcodeImagePath = false;
|
||||
|
||||
private boolean destroyed = false;
|
||||
private boolean showDialogIfMissingCameraPermission = true;
|
||||
private String missingCameraPermissionDialogMessage = "";
|
||||
|
||||
// Delay long enough that the beep can be played.
|
||||
// TODO: play beep in background
|
||||
private static final long DELAY_BEEP = 150;
|
||||
private boolean destroyed = false;
|
||||
|
||||
private InactivityTimer inactivityTimer;
|
||||
private BeepManager beepManager;
|
||||
|
||||
private Handler handler;
|
||||
|
||||
private boolean finishWhenClosed = false;
|
||||
|
||||
private BarcodeCallback callback = new BarcodeCallback() {
|
||||
@Override
|
||||
public void barcodeResult(final BarcodeResult result) {
|
||||
barcodeView.pause();
|
||||
beepManager.playBeepSoundAndVibrate();
|
||||
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
returnResult(result);
|
||||
}
|
||||
}, DELAY_BEEP);
|
||||
|
||||
handler.post(() -> returnResult(result));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,7 +106,17 @@ public class CaptureManager {
|
||||
|
||||
@Override
|
||||
public void cameraError(Exception error) {
|
||||
displayFrameworkBugMessageAndExit();
|
||||
displayFrameworkBugMessageAndExit(
|
||||
activity.getString(R.string.zxing_msg_camera_framework_bug)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cameraClosed() {
|
||||
if (finishWhenClosed) {
|
||||
Log.d(TAG, "Camera closed; finishing activity");
|
||||
finish();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -123,12 +127,9 @@ public class CaptureManager {
|
||||
|
||||
handler = new Handler();
|
||||
|
||||
inactivityTimer = new InactivityTimer(activity, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(TAG, "Finishing due to inactivity");
|
||||
finish();
|
||||
}
|
||||
inactivityTimer = new InactivityTimer(activity, () -> {
|
||||
Log.d(TAG, "Finishing due to inactivity");
|
||||
finish();
|
||||
});
|
||||
|
||||
beepManager = new BeepManager(activity);
|
||||
@@ -151,14 +152,11 @@ public class CaptureManager {
|
||||
this.orientationLock = savedInstanceState.getInt(SAVED_ORIENTATION_LOCK, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||
}
|
||||
|
||||
if(intent != null) {
|
||||
if (orientationLock == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
|
||||
// Only lock the orientation if it's not locked to something else yet
|
||||
boolean orientationLocked = intent.getBooleanExtra(Intents.Scan.ORIENTATION_LOCKED, true);
|
||||
|
||||
if (orientationLocked) {
|
||||
lockOrientation();
|
||||
}
|
||||
if (intent != null) {
|
||||
// Only lock the orientation if it's not locked to something else yet
|
||||
boolean orientationLocked = intent.getBooleanExtra(Intents.Scan.ORIENTATION_LOCKED, true);
|
||||
if (orientationLocked) {
|
||||
lockOrientation();
|
||||
}
|
||||
|
||||
if (Intents.Scan.ACTION.equals(intent.getAction())) {
|
||||
@@ -167,17 +165,17 @@ public class CaptureManager {
|
||||
|
||||
if (!intent.getBooleanExtra(Intents.Scan.BEEP_ENABLED, true)) {
|
||||
beepManager.setBeepEnabled(false);
|
||||
beepManager.updatePrefs();
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intents.Scan.SHOW_MISSING_CAMERA_PERMISSION_DIALOG)) {
|
||||
setShowMissingCameraPermissionDialog(
|
||||
intent.getBooleanExtra(Intents.Scan.SHOW_MISSING_CAMERA_PERMISSION_DIALOG, true),
|
||||
intent.getStringExtra(Intents.Scan.MISSING_CAMERA_PERMISSION_DIALOG_MESSAGE)
|
||||
);
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intents.Scan.TIMEOUT)) {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
returnResultTimeout();
|
||||
}
|
||||
};
|
||||
handler.postDelayed(runnable, intent.getLongExtra(Intents.Scan.TIMEOUT, 0L));
|
||||
handler.postDelayed(this::returnResultTimeout, intent.getLongExtra(Intents.Scan.TIMEOUT, 0L));
|
||||
}
|
||||
|
||||
if (intent.getBooleanExtra(Intents.Scan.BARCODE_IMAGE_ENABLED, false)) {
|
||||
@@ -228,12 +226,11 @@ public class CaptureManager {
|
||||
* Call from Activity#onResume().
|
||||
*/
|
||||
public void onResume() {
|
||||
if(Build.VERSION.SDK_INT >= 23) {
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
openCameraWithPermission();
|
||||
} else {
|
||||
barcodeView.resume();
|
||||
}
|
||||
beepManager.updatePrefs();
|
||||
inactivityTimer.start();
|
||||
}
|
||||
|
||||
@@ -244,43 +241,46 @@ public class CaptureManager {
|
||||
if (ContextCompat.checkSelfPermission(this.activity, Manifest.permission.CAMERA)
|
||||
== PackageManager.PERMISSION_GRANTED) {
|
||||
barcodeView.resume();
|
||||
} else if(!askedPermission) {
|
||||
} else if (!askedPermission) {
|
||||
ActivityCompat.requestPermissions(this.activity,
|
||||
new String[]{Manifest.permission.CAMERA},
|
||||
cameraPermissionReqCode);
|
||||
askedPermission = true;
|
||||
} else {
|
||||
// Wait for permission result
|
||||
}
|
||||
} // else wait for permission result
|
||||
}
|
||||
|
||||
/**
|
||||
* Call from Activity#onRequestPermissionsResult
|
||||
* @param requestCode
|
||||
* @param permissions
|
||||
* @param grantResults
|
||||
* @param requestCode The request code passed in {@link androidx.core.app.ActivityCompat#requestPermissions(Activity, String[], int)}.
|
||||
* @param permissions The requested permissions.
|
||||
* @param grantResults The grant results for the corresponding permissions
|
||||
* which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED}
|
||||
* or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null.
|
||||
*/
|
||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
||||
if(requestCode == cameraPermissionReqCode) {
|
||||
if (requestCode == cameraPermissionReqCode) {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
// permission was granted
|
||||
barcodeView.resume();
|
||||
} else {
|
||||
// TODO: display better error message.
|
||||
displayFrameworkBugMessageAndExit();
|
||||
setMissingCameraPermissionResult();
|
||||
|
||||
if (showDialogIfMissingCameraPermission) {
|
||||
displayFrameworkBugMessageAndExit(missingCameraPermissionDialogMessage);
|
||||
} else {
|
||||
closeAndFinish();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call from Activity#onPause().
|
||||
*/
|
||||
public void onPause() {
|
||||
barcodeView.pause();
|
||||
|
||||
inactivityTimer.cancel();
|
||||
beepManager.close();
|
||||
barcodeView.pauseAndWait();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -289,6 +289,7 @@ public class CaptureManager {
|
||||
public void onDestroy() {
|
||||
destroyed = true;
|
||||
inactivityTimer.cancel();
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -298,7 +299,6 @@ public class CaptureManager {
|
||||
outState.putInt(SAVED_ORIENTATION_LOCK, this.orientationLock);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a intent to return as the Activity result.
|
||||
*
|
||||
@@ -373,38 +373,50 @@ public class CaptureManager {
|
||||
activity.finish();
|
||||
}
|
||||
|
||||
protected void closeAndFinish() {
|
||||
if (barcodeView.getBarcodeView().isCameraClosed()) {
|
||||
finish();
|
||||
} else {
|
||||
finishWhenClosed = true;
|
||||
}
|
||||
|
||||
barcodeView.pause();
|
||||
inactivityTimer.cancel();
|
||||
}
|
||||
|
||||
private void setMissingCameraPermissionResult() {
|
||||
Intent intent = new Intent(Intents.Scan.ACTION);
|
||||
intent.putExtra(Intents.Scan.MISSING_CAMERA_PERMISSION, true);
|
||||
activity.setResult(Activity.RESULT_CANCELED, intent);
|
||||
}
|
||||
|
||||
protected void returnResultTimeout() {
|
||||
Intent intent = new Intent(Intents.Scan.ACTION);
|
||||
intent.putExtra(Intents.Scan.TIMEOUT, true);
|
||||
activity.setResult(Activity.RESULT_CANCELED, intent);
|
||||
finish();
|
||||
closeAndFinish();
|
||||
}
|
||||
|
||||
protected void returnResult(BarcodeResult rawResult) {
|
||||
Intent intent = resultIntent(rawResult, getBarcodeImagePath(rawResult));
|
||||
activity.setResult(Activity.RESULT_OK, intent);
|
||||
finish();
|
||||
closeAndFinish();
|
||||
}
|
||||
|
||||
protected void displayFrameworkBugMessageAndExit() {
|
||||
if (activity.isFinishing() || this.destroyed) {
|
||||
protected void displayFrameworkBugMessageAndExit(String message) {
|
||||
if (activity.isFinishing() || this.destroyed || finishWhenClosed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.isEmpty()) {
|
||||
message = activity.getString(R.string.zxing_msg_camera_framework_bug);
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setTitle(activity.getString(R.string.zxing_app_name));
|
||||
builder.setMessage(activity.getString(R.string.zxing_msg_camera_framework_bug));
|
||||
builder.setPositiveButton(R.string.zxing_button_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setMessage(message);
|
||||
builder.setPositiveButton(R.string.zxing_button_ok, (dialog, which) -> finish());
|
||||
builder.setOnCancelListener(dialog -> finish());
|
||||
builder.show();
|
||||
}
|
||||
|
||||
@@ -415,4 +427,29 @@ public class CaptureManager {
|
||||
public static void setCameraPermissionReqCode(int cameraPermissionReqCode) {
|
||||
CaptureManager.cameraPermissionReqCode = cameraPermissionReqCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* If set to true, shows the default error dialog if camera permission is missing.
|
||||
* <p>
|
||||
* If set to false, instead the capture manager just finishes.
|
||||
* <p>
|
||||
* In both cases, the activity result is set to {@link Intents.Scan#MISSING_CAMERA_PERMISSION}
|
||||
* and cancelled
|
||||
*/
|
||||
public void setShowMissingCameraPermissionDialog(boolean visible) {
|
||||
setShowMissingCameraPermissionDialog(visible, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* If set to true, shows the specified error dialog message if camera permission is missing.
|
||||
* <p>
|
||||
* If set to false, instead the capture manager just finishes.
|
||||
* <p>
|
||||
* In both cases, the activity result is set to {@link Intents.Scan#MISSING_CAMERA_PERMISSION}
|
||||
* and cancelled
|
||||
*/
|
||||
public void setShowMissingCameraPermissionDialog(boolean visible, String message) {
|
||||
showDialogIfMissingCameraPermission = visible;
|
||||
missingCameraPermissionDialogMessage = message != null ? message : "";
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ public class DecoderResultPointCallback implements ResultPointCallback {
|
||||
|
||||
@Override
|
||||
public void foundPossibleResultPoint(ResultPoint point) {
|
||||
if(decoder != null) {
|
||||
if (decoder != null) {
|
||||
decoder.foundPossibleResultPoint(point);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,9 @@ public class DecoderThread {
|
||||
public boolean handleMessage(Message message) {
|
||||
if (message.what == R.id.zxing_decode) {
|
||||
decode((SourceData) message.obj);
|
||||
} else if (message.what == R.id.zxing_preview_failed) {
|
||||
// Error already logged. Try again.
|
||||
requestNextPreview();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -80,7 +83,6 @@ public class DecoderThread {
|
||||
requestNextPreview();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stop decoding.
|
||||
*
|
||||
@@ -96,7 +98,6 @@ public class DecoderThread {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final PreviewCallback previewCallback = new PreviewCallback() {
|
||||
@Override
|
||||
public void onPreview(SourceData sourceData) {
|
||||
@@ -111,12 +112,20 @@ public class DecoderThread {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreviewError(Exception e) {
|
||||
synchronized (LOCK) {
|
||||
if (running) {
|
||||
// Post to our thread.
|
||||
handler.obtainMessage(R.id.zxing_preview_failed).sendToTarget();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void requestNextPreview() {
|
||||
if (cameraInstance.isOpen()) {
|
||||
cameraInstance.requestPreview(previewCallback);
|
||||
}
|
||||
cameraInstance.requestPreview(previewCallback);
|
||||
}
|
||||
|
||||
protected LuminanceSource createSource(SourceData sourceData) {
|
||||
@@ -133,7 +142,7 @@ public class DecoderThread {
|
||||
sourceData.setCropRect(cropRect);
|
||||
LuminanceSource source = createSource(sourceData);
|
||||
|
||||
if(source != null) {
|
||||
if (source != null) {
|
||||
rawResult = decoder.decode(source);
|
||||
}
|
||||
|
||||
@@ -155,11 +164,10 @@ public class DecoderThread {
|
||||
}
|
||||
}
|
||||
if (resultHandler != null) {
|
||||
List<ResultPoint> resultPoints = decoder.getPossibleResultPoints();
|
||||
Message message = Message.obtain(resultHandler, R.id.zxing_possible_result_points, resultPoints);
|
||||
List<ResultPoint> resultPoints = BarcodeResult.transformResultPoints(decoder.getPossibleResultPoints(), sourceData);
|
||||
Message message = Message.obtain(resultHandler, R.id.zxing_possible_result_points, resultPoints);
|
||||
message.sendToTarget();
|
||||
}
|
||||
requestNextPreview();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+50
-12
@@ -16,6 +16,7 @@ import com.google.zxing.client.android.DecodeFormatManager;
|
||||
import com.google.zxing.client.android.DecodeHintManager;
|
||||
import com.google.zxing.client.android.Intents;
|
||||
import com.google.zxing.client.android.R;
|
||||
import com.journeyapps.barcodescanner.camera.CameraParametersCallback;
|
||||
import com.journeyapps.barcodescanner.camera.CameraSettings;
|
||||
|
||||
import java.util.List;
|
||||
@@ -89,7 +90,7 @@ public class DecoratedBarcodeView extends FrameLayout {
|
||||
|
||||
inflate(getContext(), scannerLayout, this);
|
||||
|
||||
barcodeView = (BarcodeView) findViewById(R.id.zxing_barcode_surface);
|
||||
barcodeView = findViewById(R.id.zxing_barcode_surface);
|
||||
|
||||
if (barcodeView == null) {
|
||||
throw new IllegalArgumentException(
|
||||
@@ -101,7 +102,7 @@ public class DecoratedBarcodeView extends FrameLayout {
|
||||
barcodeView.initializeAttributes(attrs);
|
||||
|
||||
|
||||
viewFinder = (ViewfinderView) findViewById(R.id.zxing_viewfinder_view);
|
||||
viewFinder = findViewById(R.id.zxing_viewfinder_view);
|
||||
|
||||
if (viewFinder == null) {
|
||||
throw new IllegalArgumentException(
|
||||
@@ -112,11 +113,11 @@ public class DecoratedBarcodeView extends FrameLayout {
|
||||
viewFinder.setCameraPreview(barcodeView);
|
||||
|
||||
// statusView is optional
|
||||
statusView = (TextView) findViewById(R.id.zxing_status_view);
|
||||
statusView = findViewById(R.id.zxing_status_view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize with no custom attributes setted.
|
||||
* Initialize with no custom attributes set.
|
||||
*/
|
||||
private void initialize() {
|
||||
initialize(null);
|
||||
@@ -141,28 +142,52 @@ public class DecoratedBarcodeView extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intents.Scan.TORCH_ENABLED)) {
|
||||
if (intent.getBooleanExtra(Intents.Scan.TORCH_ENABLED, false)) {
|
||||
this.setTorchOn();
|
||||
}
|
||||
}
|
||||
|
||||
String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
|
||||
if (customPromptMessage != null) {
|
||||
setStatusText(customPromptMessage);
|
||||
}
|
||||
|
||||
// Check what type of scan. Default: normal scan
|
||||
int scanType = intent.getIntExtra(Intents.Scan.SCAN_TYPE, 0);
|
||||
|
||||
String characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);
|
||||
|
||||
MultiFormatReader reader = new MultiFormatReader();
|
||||
reader.setHints(decodeHints);
|
||||
|
||||
barcodeView.setCameraSettings(settings);
|
||||
barcodeView.setDecoderFactory(new DefaultDecoderFactory(decodeFormats, decodeHints, characterSet));
|
||||
barcodeView.setDecoderFactory(new DefaultDecoderFactory(decodeFormats, decodeHints, characterSet, scanType));
|
||||
}
|
||||
|
||||
public void setCameraSettings(CameraSettings cameraSettings) {
|
||||
barcodeView.setCameraSettings(cameraSettings);
|
||||
}
|
||||
|
||||
public void setDecoderFactory(DecoderFactory decoderFactory) {
|
||||
barcodeView.setDecoderFactory(decoderFactory);
|
||||
}
|
||||
|
||||
public DecoderFactory getDecoderFactory() {
|
||||
return barcodeView.getDecoderFactory();
|
||||
}
|
||||
|
||||
public CameraSettings getCameraSettings() {
|
||||
return barcodeView.getCameraSettings();
|
||||
}
|
||||
|
||||
public void setStatusText(String text) {
|
||||
// statusView is optional when using a custom layout
|
||||
if(statusView != null) {
|
||||
if (statusView != null) {
|
||||
statusView.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see BarcodeView#pause()
|
||||
*/
|
||||
@@ -170,6 +195,13 @@ public class DecoratedBarcodeView extends FrameLayout {
|
||||
barcodeView.pause();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BarcodeView#pauseAndWait()
|
||||
*/
|
||||
public void pauseAndWait() {
|
||||
barcodeView.pauseAndWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BarcodeView#resume()
|
||||
*/
|
||||
@@ -178,7 +210,7 @@ public class DecoratedBarcodeView extends FrameLayout {
|
||||
}
|
||||
|
||||
public BarcodeView getBarcodeView() {
|
||||
return (BarcodeView) findViewById(R.id.zxing_barcode_surface);
|
||||
return findViewById(R.id.zxing_barcode_surface);
|
||||
}
|
||||
|
||||
public ViewfinderView getViewFinder() {
|
||||
@@ -189,13 +221,11 @@ public class DecoratedBarcodeView extends FrameLayout {
|
||||
return statusView;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see BarcodeView#decodeSingle(BarcodeCallback)
|
||||
*/
|
||||
public void decodeSingle(BarcodeCallback callback) {
|
||||
barcodeView.decodeSingle(new WrappedCallback(callback));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,6 +257,16 @@ public class DecoratedBarcodeView extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the settings for Camera.
|
||||
* Must be called after {@link #resume()}.
|
||||
*
|
||||
* @param callback {@link CameraParametersCallback}
|
||||
*/
|
||||
public void changeCameraParameters(CameraParametersCallback callback) {
|
||||
barcodeView.changeCameraParameters(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles focus, camera, volume up and volume down keys.
|
||||
*
|
||||
@@ -262,7 +302,5 @@ public class DecoratedBarcodeView extends FrameLayout {
|
||||
void onTorchOn();
|
||||
|
||||
void onTorchOff();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+25
-4
@@ -15,14 +15,22 @@ public class DefaultDecoderFactory implements DecoderFactory {
|
||||
private Collection<BarcodeFormat> decodeFormats;
|
||||
private Map<DecodeHintType, ?> hints;
|
||||
private String characterSet;
|
||||
private int scanType;
|
||||
|
||||
public DefaultDecoderFactory() {
|
||||
}
|
||||
|
||||
public DefaultDecoderFactory(Collection<BarcodeFormat> decodeFormats, Map<DecodeHintType, ?> hints, String characterSet) {
|
||||
|
||||
|
||||
public DefaultDecoderFactory(Collection<BarcodeFormat> decodeFormats) {
|
||||
this.decodeFormats = decodeFormats;
|
||||
}
|
||||
|
||||
public DefaultDecoderFactory(Collection<BarcodeFormat> decodeFormats, Map<DecodeHintType, ?> hints, String characterSet, int scanType) {
|
||||
this.decodeFormats = decodeFormats;
|
||||
this.hints = hints;
|
||||
this.characterSet = characterSet;
|
||||
this.scanType = scanType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -31,11 +39,11 @@ public class DefaultDecoderFactory implements DecoderFactory {
|
||||
|
||||
hints.putAll(baseHints);
|
||||
|
||||
if(this.hints != null) {
|
||||
if (this.hints != null) {
|
||||
hints.putAll(this.hints);
|
||||
}
|
||||
|
||||
if(this.decodeFormats != null) {
|
||||
if (this.decodeFormats != null) {
|
||||
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
|
||||
}
|
||||
|
||||
@@ -46,6 +54,19 @@ public class DefaultDecoderFactory implements DecoderFactory {
|
||||
MultiFormatReader reader = new MultiFormatReader();
|
||||
reader.setHints(hints);
|
||||
|
||||
return new Decoder(reader);
|
||||
switch (scanType){
|
||||
case 0:
|
||||
return new Decoder(reader);
|
||||
case 1:
|
||||
return new InvertedDecoder(reader);
|
||||
case 2:
|
||||
return new MixedDecoder(reader);
|
||||
default:
|
||||
return new Decoder(reader);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.journeyapps.barcodescanner;
|
||||
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.LuminanceSource;
|
||||
import com.google.zxing.Reader;
|
||||
import com.google.zxing.common.HybridBinarizer;
|
||||
|
||||
/**
|
||||
* Created by leighmd on 11/2/16.
|
||||
*/
|
||||
public class InvertedDecoder extends Decoder {
|
||||
|
||||
/**
|
||||
* Create a new Decoder with the specified Reader.
|
||||
* <p/>
|
||||
* It is recommended to use an instance of MultiFormatReader in most cases.
|
||||
*
|
||||
* @param reader the reader
|
||||
*/
|
||||
public InvertedDecoder(Reader reader) {
|
||||
super(reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an image source, convert to a binary bitmap.
|
||||
*
|
||||
* Override this to use a custom binarizer.
|
||||
*
|
||||
* @param source the image source
|
||||
* @return a BinaryBitmap
|
||||
*/
|
||||
protected BinaryBitmap toBitmap(LuminanceSource source) {
|
||||
|
||||
return new BinaryBitmap(new HybridBinarizer(source.invert()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.journeyapps.barcodescanner;
|
||||
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.LuminanceSource;
|
||||
import com.google.zxing.Reader;
|
||||
import com.google.zxing.common.HybridBinarizer;
|
||||
|
||||
/**
|
||||
* Decoder that performs alternating scans in normal mode and inverted mode.
|
||||
*/
|
||||
public class MixedDecoder extends Decoder {
|
||||
private boolean isInverted = true;
|
||||
|
||||
/**
|
||||
* Create a new Decoder with the specified Reader.
|
||||
* <p/>
|
||||
* It is recommended to use an instance of MultiFormatReader in most cases.
|
||||
*
|
||||
* @param reader the reader
|
||||
*/
|
||||
public MixedDecoder(Reader reader) {
|
||||
super(reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an image source, convert to a binary bitmap.
|
||||
*
|
||||
* Override this to use a custom binarizer.
|
||||
*
|
||||
* @param source the image source
|
||||
* @return a BinaryBitmap
|
||||
*/
|
||||
protected BinaryBitmap toBitmap(LuminanceSource source) {
|
||||
if (isInverted) {
|
||||
isInverted = false;
|
||||
return new BinaryBitmap(new HybridBinarizer(source.invert()));
|
||||
} else {
|
||||
isInverted = true;
|
||||
return new BinaryBitmap(new HybridBinarizer(source));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.journeyapps.barcodescanner;
|
||||
|
||||
import android.graphics.Rect;
|
||||
|
||||
public class RawImageData {
|
||||
private byte[] data;
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public RawImageData(byte[] data, int width, int height) {
|
||||
this.data = data;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public RawImageData cropAndScale(Rect cropRect, int scale) {
|
||||
int width = cropRect.width() / scale;
|
||||
int height = cropRect.height() / scale;
|
||||
|
||||
int top = cropRect.top;
|
||||
|
||||
int area = width * height;
|
||||
byte[] matrix = new byte[area];
|
||||
|
||||
if (scale == 1) {
|
||||
int inputOffset = top * this.width + cropRect.left;
|
||||
|
||||
// Copy one cropped row at a time.
|
||||
for (int y = 0; y < height; y++) {
|
||||
int outputOffset = y * width;
|
||||
System.arraycopy(this.data, inputOffset, matrix, outputOffset, width);
|
||||
inputOffset += this.width;
|
||||
}
|
||||
} else {
|
||||
int inputOffset = top * this.width + cropRect.left;
|
||||
|
||||
// Copy one cropped row at a time.
|
||||
for (int y = 0; y < height; y++) {
|
||||
int outputOffset = y * width;
|
||||
int xOffset = inputOffset;
|
||||
for (int x = 0; x < width; x++) {
|
||||
matrix[outputOffset] = this.data[xOffset];
|
||||
xOffset += scale;
|
||||
outputOffset += 1;
|
||||
}
|
||||
inputOffset += this.width * scale;
|
||||
}
|
||||
}
|
||||
return new RawImageData(matrix, width, height);
|
||||
}
|
||||
|
||||
|
||||
public RawImageData rotateCameraPreview(int cameraRotation) {
|
||||
switch (cameraRotation) {
|
||||
case 90:
|
||||
return new RawImageData(rotateCW(data, this.width, this.height), this.height, this.width);
|
||||
case 180:
|
||||
return new RawImageData(rotate180(data, this.width, this.height), this.width, this.height);
|
||||
case 270:
|
||||
return new RawImageData(rotateCCW(data, this.width, this.height), this.height, this.width);
|
||||
case 0:
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate an image by 90 degrees CW.
|
||||
*
|
||||
* @param data the image data, in with the first width * height bytes being the luminance data.
|
||||
* @param imageWidth the width of the image
|
||||
* @param imageHeight the height of the image
|
||||
* @return the rotated bytes
|
||||
*/
|
||||
public static byte[] rotateCW(byte[] data, int imageWidth, int imageHeight) {
|
||||
// Adapted from http://stackoverflow.com/a/15775173
|
||||
// data may contain more than just y (u and v), but we are only interested in the y section.
|
||||
|
||||
byte[] yuv = new byte[imageWidth * imageHeight];
|
||||
int i = 0;
|
||||
for (int x = 0; x < imageWidth; x++) {
|
||||
for (int y = imageHeight - 1; y >= 0; y--) {
|
||||
yuv[i] = data[y * imageWidth + x];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return yuv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate an image by 180 degrees.
|
||||
*
|
||||
* @param data the image data, in with the first width * height bytes being the luminance data.
|
||||
* @param imageWidth the width of the image
|
||||
* @param imageHeight the height of the image
|
||||
* @return the rotated bytes
|
||||
*/
|
||||
public static byte[] rotate180(byte[] data, int imageWidth, int imageHeight) {
|
||||
int n = imageWidth * imageHeight;
|
||||
byte[] yuv = new byte[n];
|
||||
|
||||
int i = n - 1;
|
||||
for (int j = 0; j < n; j++) {
|
||||
yuv[i] = data[j];
|
||||
i--;
|
||||
}
|
||||
return yuv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate an image by 90 degrees CCW.
|
||||
*
|
||||
* @param data the image data, in with the first width * height bytes being the luminance data.
|
||||
* @param imageWidth the width of the image
|
||||
* @param imageHeight the height of the image
|
||||
* @return the rotated bytes
|
||||
*/
|
||||
public static byte[] rotateCCW(byte[] data, int imageWidth, int imageHeight) {
|
||||
int n = imageWidth * imageHeight;
|
||||
byte[] yuv = new byte[n];
|
||||
int i = n - 1;
|
||||
for (int x = 0; x < imageWidth; x++) {
|
||||
for (int y = imageHeight - 1; y >= 0; y--) {
|
||||
yuv[i] = data[y * imageWidth + x];
|
||||
i--;
|
||||
}
|
||||
}
|
||||
return yuv;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.journeyapps.barcodescanner;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.SensorManager;
|
||||
import android.util.Log;
|
||||
import android.view.OrientationEventListener;
|
||||
import android.view.WindowManager;
|
||||
|
||||
@@ -23,7 +22,6 @@ public class RotationListener {
|
||||
public RotationListener() {
|
||||
}
|
||||
|
||||
|
||||
public void listen(Context context, RotationCallback callback) {
|
||||
// Stop to make sure we're not registering the listening twice.
|
||||
stop();
|
||||
@@ -42,7 +40,7 @@ public class RotationListener {
|
||||
public void onOrientationChanged(int orientation) {
|
||||
WindowManager localWindowManager = windowManager;
|
||||
RotationCallback localCallback = RotationListener.this.callback;
|
||||
if(windowManager != null && localCallback != null) {
|
||||
if (windowManager != null && localCallback != null) {
|
||||
int newRotation = localWindowManager.getDefaultDisplay().getRotation();
|
||||
if (newRotation != lastRotation) {
|
||||
lastRotation = newRotation;
|
||||
@@ -59,7 +57,7 @@ public class RotationListener {
|
||||
public void stop() {
|
||||
// To reduce the effect of possible leaks, we clear any references we have to external
|
||||
// objects.
|
||||
if(this.orientationEventListener != null) {
|
||||
if (this.orientationEventListener != null) {
|
||||
this.orientationEventListener.disable();
|
||||
}
|
||||
this.orientationEventListener = null;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.journeyapps.barcodescanner;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.activity.result.contract.ActivityResultContract;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class ScanContract extends ActivityResultContract<ScanOptions, ScanIntentResult> {
|
||||
@NonNull
|
||||
@Override
|
||||
public Intent createIntent(@NonNull Context context, ScanOptions input) {
|
||||
return input.createScanIntent(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScanIntentResult parseResult(int resultCode, @Nullable Intent intent) {
|
||||
return ScanIntentResult.parseActivityResult(resultCode, intent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Based on IntentResult.
|
||||
*
|
||||
* Copyright 2009 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.journeyapps.barcodescanner;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.google.zxing.client.android.Intents;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
/**
|
||||
* <p>Encapsulates the result of a barcode scan invoked through {@link ScanContract}.</p>
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class ScanIntentResult {
|
||||
|
||||
private final String contents;
|
||||
private final String formatName;
|
||||
private final byte[] rawBytes;
|
||||
private final Integer orientation;
|
||||
private final String errorCorrectionLevel;
|
||||
private final String barcodeImagePath;
|
||||
private final Intent originalIntent;
|
||||
|
||||
ScanIntentResult() {
|
||||
this(null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
ScanIntentResult(Intent intent) {
|
||||
this(null, null, null, null, null, null, intent);
|
||||
}
|
||||
|
||||
ScanIntentResult(String contents,
|
||||
String formatName,
|
||||
byte[] rawBytes,
|
||||
Integer orientation,
|
||||
String errorCorrectionLevel,
|
||||
String barcodeImagePath,
|
||||
Intent originalIntent) {
|
||||
this.contents = contents;
|
||||
this.formatName = formatName;
|
||||
this.rawBytes = rawBytes;
|
||||
this.orientation = orientation;
|
||||
this.errorCorrectionLevel = errorCorrectionLevel;
|
||||
this.barcodeImagePath = barcodeImagePath;
|
||||
this.originalIntent = originalIntent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return raw content of barcode
|
||||
*/
|
||||
public String getContents() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return name of format, like "QR_CODE", "UPC_A". See {@code BarcodeFormat} for more format names.
|
||||
*/
|
||||
public String getFormatName() {
|
||||
return formatName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return raw bytes of the barcode content, if applicable, or null otherwise
|
||||
*/
|
||||
public byte[] getRawBytes() {
|
||||
return rawBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return rotation of the image, in degrees, which resulted in a successful scan. May be null.
|
||||
*/
|
||||
public Integer getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return name of the error correction level used in the barcode, if applicable
|
||||
*/
|
||||
public String getErrorCorrectionLevel() {
|
||||
return errorCorrectionLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return path to a temporary file containing the barcode image, if applicable, or null otherwise
|
||||
*/
|
||||
public String getBarcodeImagePath() {
|
||||
return barcodeImagePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the original intent
|
||||
*/
|
||||
public Intent getOriginalIntent() {
|
||||
return originalIntent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
int rawBytesLength = rawBytes == null ? 0 : rawBytes.length;
|
||||
return "Format: " + formatName + '\n' +
|
||||
"Contents: " + contents + '\n' +
|
||||
"Raw bytes: (" + rawBytesLength + " bytes)\n" +
|
||||
"Orientation: " + orientation + '\n' +
|
||||
"EC level: " + errorCorrectionLevel + '\n' +
|
||||
"Barcode image: " + barcodeImagePath + '\n' +
|
||||
"Original intent: " + originalIntent + '\n';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse activity result, without checking the request code.
|
||||
*
|
||||
* @param resultCode result code from {@code onActivityResult()}
|
||||
* @param intent {@link Intent} from {@code onActivityResult()}
|
||||
* @return an {@link IntentResult} containing the result of the scan. If the user cancelled scanning,
|
||||
* the fields will be null.
|
||||
*/
|
||||
public static ScanIntentResult parseActivityResult(int resultCode, Intent intent) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
String contents = intent.getStringExtra(Intents.Scan.RESULT);
|
||||
String formatName = intent.getStringExtra(Intents.Scan.RESULT_FORMAT);
|
||||
byte[] rawBytes = intent.getByteArrayExtra(Intents.Scan.RESULT_BYTES);
|
||||
int intentOrientation = intent.getIntExtra(Intents.Scan.RESULT_ORIENTATION, Integer.MIN_VALUE);
|
||||
Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation;
|
||||
String errorCorrectionLevel = intent.getStringExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL);
|
||||
String barcodeImagePath = intent.getStringExtra(Intents.Scan.RESULT_BARCODE_IMAGE_PATH);
|
||||
return new ScanIntentResult(contents,
|
||||
formatName,
|
||||
rawBytes,
|
||||
orientation,
|
||||
errorCorrectionLevel,
|
||||
barcodeImagePath,
|
||||
intent);
|
||||
}
|
||||
return new ScanIntentResult(intent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* Based on IntentIntegrator, Copyright 2009 ZXing authors.
|
||||
*
|
||||
*/
|
||||
package com.journeyapps.barcodescanner;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.google.zxing.client.android.Intents;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ScanOptions {
|
||||
// supported barcode formats
|
||||
|
||||
// Product Codes
|
||||
public static final String UPC_A = "UPC_A";
|
||||
public static final String UPC_E = "UPC_E";
|
||||
public static final String EAN_8 = "EAN_8";
|
||||
public static final String EAN_13 = "EAN_13";
|
||||
public static final String RSS_14 = "RSS_14";
|
||||
|
||||
// Other 1D
|
||||
public static final String CODE_39 = "CODE_39";
|
||||
public static final String CODE_93 = "CODE_93";
|
||||
public static final String CODE_128 = "CODE_128";
|
||||
public static final String ITF = "ITF";
|
||||
|
||||
public static final String RSS_EXPANDED = "RSS_EXPANDED";
|
||||
|
||||
// 2D
|
||||
public static final String QR_CODE = "QR_CODE";
|
||||
public static final String DATA_MATRIX = "DATA_MATRIX";
|
||||
public static final String PDF_417 = "PDF_417";
|
||||
|
||||
|
||||
public static final Collection<String> PRODUCT_CODE_TYPES = list(UPC_A, UPC_E, EAN_8, EAN_13, RSS_14);
|
||||
public static final Collection<String> ONE_D_CODE_TYPES =
|
||||
list(UPC_A, UPC_E, EAN_8, EAN_13, RSS_14, CODE_39, CODE_93, CODE_128,
|
||||
ITF, RSS_14, RSS_EXPANDED);
|
||||
|
||||
public static final Collection<String> ALL_CODE_TYPES = null;
|
||||
|
||||
private final Map<String, Object> moreExtras = new HashMap<>(3);
|
||||
|
||||
private Collection<String> desiredBarcodeFormats;
|
||||
|
||||
private Class<?> captureActivity;
|
||||
|
||||
|
||||
protected Class<?> getDefaultCaptureActivity() {
|
||||
return CaptureActivity.class;
|
||||
}
|
||||
|
||||
public ScanOptions() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Class<?> getCaptureActivity() {
|
||||
if (captureActivity == null) {
|
||||
captureActivity = getDefaultCaptureActivity();
|
||||
}
|
||||
return captureActivity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Activity class to use. It can be any activity, but should handle the intent extras
|
||||
* as used here.
|
||||
*
|
||||
* @param captureActivity the class
|
||||
*/
|
||||
public ScanOptions setCaptureActivity(Class<?> captureActivity) {
|
||||
this.captureActivity = captureActivity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<String, ?> getMoreExtras() {
|
||||
return moreExtras;
|
||||
}
|
||||
|
||||
public final ScanOptions addExtra(String key, Object value) {
|
||||
moreExtras.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a prompt to display on the capture screen, instead of using the default.
|
||||
*
|
||||
* @param prompt the prompt to display
|
||||
*/
|
||||
public final ScanOptions setPrompt(String prompt) {
|
||||
if (prompt != null) {
|
||||
addExtra(Intents.Scan.PROMPT_MESSAGE, prompt);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, the orientation is locked. Set to false to not lock.
|
||||
*
|
||||
* @param locked true to lock orientation
|
||||
*/
|
||||
public ScanOptions setOrientationLocked(boolean locked) {
|
||||
addExtra(Intents.Scan.ORIENTATION_LOCKED, locked);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the specified camera ID.
|
||||
*
|
||||
* @param cameraId camera ID of the camera to use. A negative value means "no preference".
|
||||
* @return this
|
||||
*/
|
||||
public ScanOptions setCameraId(int cameraId) {
|
||||
if (cameraId >= 0) {
|
||||
addExtra(Intents.Scan.CAMERA_ID, cameraId);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to true to enable initial torch
|
||||
*
|
||||
* @param enabled true to enable initial torch
|
||||
* @return this
|
||||
*/
|
||||
public ScanOptions setTorchEnabled(boolean enabled) {
|
||||
addExtra(Intents.Scan.TORCH_ENABLED, enabled);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set to false to disable beep on scan.
|
||||
*
|
||||
* @param enabled false to disable beep
|
||||
* @return this
|
||||
*/
|
||||
public ScanOptions setBeepEnabled(boolean enabled) {
|
||||
addExtra(Intents.Scan.BEEP_ENABLED, enabled);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to true to enable saving the barcode image and sending its path in the result Intent.
|
||||
*
|
||||
* @param enabled true to enable barcode image
|
||||
* @return this
|
||||
*/
|
||||
public ScanOptions setBarcodeImageEnabled(boolean enabled) {
|
||||
addExtra(Intents.Scan.BARCODE_IMAGE_ENABLED, enabled);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the desired barcode formats to scan.
|
||||
*
|
||||
* @param desiredBarcodeFormats names of {@code BarcodeFormat}s to scan for
|
||||
* @return this
|
||||
*/
|
||||
public ScanOptions setDesiredBarcodeFormats(Collection<String> desiredBarcodeFormats) {
|
||||
this.desiredBarcodeFormats = desiredBarcodeFormats;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the desired barcode formats to scan.
|
||||
*
|
||||
* @param desiredBarcodeFormats names of {@code BarcodeFormat}s to scan for
|
||||
* @return this
|
||||
*/
|
||||
public ScanOptions setDesiredBarcodeFormats(String... desiredBarcodeFormats) {
|
||||
this.desiredBarcodeFormats = Arrays.asList(desiredBarcodeFormats);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates a scan for all known barcode types with the default camera.
|
||||
* And starts a timer to finish on timeout
|
||||
*
|
||||
* @return Activity.RESULT_CANCELED and true on parameter TIMEOUT.
|
||||
*/
|
||||
public ScanOptions setTimeout(long timeout) {
|
||||
addExtra(Intents.Scan.TIMEOUT, timeout);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an scan intent with the specified options.
|
||||
*
|
||||
* @return the intent
|
||||
*/
|
||||
public Intent createScanIntent(Context context) {
|
||||
Intent intentScan = new Intent(context, getCaptureActivity());
|
||||
intentScan.setAction(Intents.Scan.ACTION);
|
||||
|
||||
// check which types of codes to scan for
|
||||
if (desiredBarcodeFormats != null) {
|
||||
// set the desired barcode types
|
||||
StringBuilder joinedByComma = new StringBuilder();
|
||||
for (String format : desiredBarcodeFormats) {
|
||||
if (joinedByComma.length() > 0) {
|
||||
joinedByComma.append(',');
|
||||
}
|
||||
joinedByComma.append(format);
|
||||
}
|
||||
intentScan.putExtra(Intents.Scan.FORMATS, joinedByComma.toString());
|
||||
}
|
||||
|
||||
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
attachMoreExtras(intentScan);
|
||||
return intentScan;
|
||||
}
|
||||
|
||||
private static List<String> list(String... values) {
|
||||
return Collections.unmodifiableList(Arrays.asList(values));
|
||||
}
|
||||
|
||||
private void attachMoreExtras(Intent intent) {
|
||||
for (Map.Entry<String, Object> entry : moreExtras.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
// Kind of hacky
|
||||
if (value instanceof Integer) {
|
||||
intent.putExtra(key, (Integer) value);
|
||||
} else if (value instanceof Long) {
|
||||
intent.putExtra(key, (Long) value);
|
||||
} else if (value instanceof Boolean) {
|
||||
intent.putExtra(key, (Boolean) value);
|
||||
} else if (value instanceof Double) {
|
||||
intent.putExtra(key, (Double) value);
|
||||
} else if (value instanceof Float) {
|
||||
intent.putExtra(key, (Float) value);
|
||||
} else if (value instanceof Bundle) {
|
||||
intent.putExtra(key, (Bundle) value);
|
||||
} else if (value instanceof int[]) {
|
||||
intent.putExtra(key, (int[]) value);
|
||||
} else if (value instanceof long[]) {
|
||||
intent.putExtra(key, (long[]) value);
|
||||
} else if (value instanceof boolean[]) {
|
||||
intent.putExtra(key, (boolean[]) value);
|
||||
} else if (value instanceof double[]) {
|
||||
intent.putExtra(key, (double[]) value);
|
||||
} else if (value instanceof float[]) {
|
||||
intent.putExtra(key, (float[]) value);
|
||||
} else if (value instanceof String[]) {
|
||||
intent.putExtra(key, (String[]) value);
|
||||
} else {
|
||||
intent.putExtra(key, value.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.journeyapps.barcodescanner;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -41,7 +43,7 @@ public class Size implements Comparable<Size> {
|
||||
* @return the scaled size
|
||||
*/
|
||||
public Size scaleFit(Size into) {
|
||||
if(width * into.height >= into.width * height) {
|
||||
if (width * into.height >= into.width * height) {
|
||||
// match width
|
||||
return new Size(into.width, height * into.width / width);
|
||||
} else {
|
||||
@@ -57,7 +59,7 @@ public class Size implements Comparable<Size> {
|
||||
* @return the scaled size
|
||||
*/
|
||||
public Size scaleCrop(Size into) {
|
||||
if(width * into.height <= into.width * height) {
|
||||
if (width * into.height <= into.width * height) {
|
||||
// match width
|
||||
return new Size(into.width, height * into.width / width);
|
||||
} else {
|
||||
@@ -66,7 +68,6 @@ public class Size implements Comparable<Size> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if both dimensions of the other size are at least as large as this size.
|
||||
*
|
||||
@@ -81,7 +82,7 @@ public class Size implements Comparable<Size> {
|
||||
* Default sort order is ascending by size.
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(Size other) {
|
||||
public int compareTo(@NonNull Size other) {
|
||||
int aPixels = this.height * this.width;
|
||||
int bPixels = other.height * other.width;
|
||||
if (bPixels < aPixels) {
|
||||
@@ -104,9 +105,7 @@ public class Size implements Comparable<Size> {
|
||||
|
||||
Size size = (Size) o;
|
||||
|
||||
if (width != size.width) return false;
|
||||
return height == size.height;
|
||||
|
||||
return width == size.width && height == size.height;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.graphics.Rect;
|
||||
import android.graphics.YuvImage;
|
||||
|
||||
import com.google.zxing.PlanarYUVLuminanceSource;
|
||||
import com.google.zxing.ResultPoint;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
@@ -14,14 +15,7 @@ import java.io.ByteArrayOutputStream;
|
||||
* Raw preview data from a camera.
|
||||
*/
|
||||
public class SourceData {
|
||||
/** Raw YUV data */
|
||||
private byte[] data;
|
||||
|
||||
/** Source data width */
|
||||
private int dataWidth;
|
||||
|
||||
/** Source data height */
|
||||
private int dataHeight;
|
||||
private RawImageData data;
|
||||
|
||||
/** The format of the image data. ImageFormat.NV21 and ImageFormat.YUY2 are supported. */
|
||||
private int imageFormat;
|
||||
@@ -32,6 +26,13 @@ public class SourceData {
|
||||
/** Crop rectangle, in display orientation. */
|
||||
private Rect cropRect;
|
||||
|
||||
/**
|
||||
* Factor by which to scale down before decoding.
|
||||
*/
|
||||
private int scalingFactor = 1;
|
||||
|
||||
private boolean previewMirrored;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data the image data
|
||||
@@ -41,11 +42,12 @@ public class SourceData {
|
||||
* @param rotation camera rotation relative to display rotation, in degrees (0, 90, 180 or 270).
|
||||
*/
|
||||
public SourceData(byte[] data, int dataWidth, int dataHeight, int imageFormat, int rotation) {
|
||||
this.data = data;
|
||||
this.dataWidth = dataWidth;
|
||||
this.dataHeight = dataHeight;
|
||||
this.data = new RawImageData(data, dataWidth, dataHeight);
|
||||
this.rotation = rotation;
|
||||
this.imageFormat = imageFormat;
|
||||
if (dataWidth * dataHeight > data.length) {
|
||||
throw new IllegalArgumentException("Image data does not match the resolution. " + dataWidth + "x" + dataHeight + " > " + data.length);
|
||||
}
|
||||
}
|
||||
|
||||
public Rect getCropRect() {
|
||||
@@ -61,8 +63,24 @@ public class SourceData {
|
||||
this.cropRect = cropRect;
|
||||
}
|
||||
|
||||
public boolean isPreviewMirrored() {
|
||||
return previewMirrored;
|
||||
}
|
||||
|
||||
public void setPreviewMirrored(boolean previewMirrored) {
|
||||
this.previewMirrored = previewMirrored;
|
||||
}
|
||||
|
||||
public int getScalingFactor() {
|
||||
return scalingFactor;
|
||||
}
|
||||
|
||||
public void setScalingFactor(int scalingFactor) {
|
||||
this.scalingFactor = scalingFactor;
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
return data.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +88,7 @@ public class SourceData {
|
||||
* @return width of the data
|
||||
*/
|
||||
public int getDataWidth() {
|
||||
return dataWidth;
|
||||
return data.getWidth();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +96,16 @@ public class SourceData {
|
||||
* @return height of the data
|
||||
*/
|
||||
public int getDataHeight() {
|
||||
return dataHeight;
|
||||
return data.getHeight();
|
||||
}
|
||||
|
||||
public ResultPoint translateResultPoint(ResultPoint point) {
|
||||
float x = point.getX() * this.scalingFactor + this.cropRect.left;
|
||||
float y = point.getY() * this.scalingFactor + this.cropRect.top;
|
||||
if (previewMirrored) {
|
||||
x = data.getWidth() - x;
|
||||
}
|
||||
return new ResultPoint(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,15 +121,11 @@ public class SourceData {
|
||||
}
|
||||
|
||||
public PlanarYUVLuminanceSource createSource() {
|
||||
byte[] rotated = rotateCameraPreview(rotation, data, dataWidth, dataHeight);
|
||||
// TODO: handle mirrored (front) camera. Probably only the ResultPoints should be mirrored,
|
||||
RawImageData rotated = this.data.rotateCameraPreview(rotation);
|
||||
RawImageData scaled = rotated.cropAndScale(this.cropRect, this.scalingFactor);
|
||||
|
||||
// not the preview for decoding.
|
||||
if (isRotated()) {
|
||||
//noinspection SuspiciousNameCombination
|
||||
return new PlanarYUVLuminanceSource(rotated, dataHeight, dataWidth, cropRect.left, cropRect.top, cropRect.width(), cropRect.height(), false);
|
||||
} else {
|
||||
return new PlanarYUVLuminanceSource(rotated, dataWidth, dataHeight, cropRect.left, cropRect.top, cropRect.width(), cropRect.height(), false);
|
||||
}
|
||||
return new PlanarYUVLuminanceSource(scaled.getData(), scaled.getWidth(), scaled.getHeight(), 0, 0, scaled.getWidth(), scaled.getHeight(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,14 +147,16 @@ public class SourceData {
|
||||
return getBitmap(cropRect, scaleFactor);
|
||||
}
|
||||
|
||||
private Bitmap getBitmap(Rect cropRect, int scaleFactor) {
|
||||
if(isRotated()) {
|
||||
public Bitmap getBitmap(Rect cropRect, int scaleFactor) {
|
||||
if (cropRect == null) {
|
||||
cropRect = new Rect(0, 0, data.getWidth(), data.getHeight());
|
||||
} else if (isRotated()) {
|
||||
//noinspection SuspiciousNameCombination
|
||||
cropRect = new Rect(cropRect.top, cropRect.left, cropRect.bottom, cropRect.right);
|
||||
}
|
||||
|
||||
// TODO: there should be a way to do this without JPEG compression / decompression cycle.
|
||||
YuvImage img = new YuvImage(data, imageFormat, dataWidth, dataHeight, null);
|
||||
YuvImage img = new YuvImage(data.getData(), imageFormat, data.getWidth(), data.getHeight(), null);
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
img.compressToJpeg(cropRect, 90, buffer);
|
||||
byte[] jpegData = buffer.toByteArray();
|
||||
@@ -150,84 +175,4 @@ public class SourceData {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static byte[] rotateCameraPreview(int cameraRotation, byte[] data, int imageWidth, int imageHeight) {
|
||||
switch (cameraRotation) {
|
||||
case 0:
|
||||
return data;
|
||||
case 90:
|
||||
return rotateCW(data, imageWidth, imageHeight);
|
||||
case 180:
|
||||
return rotate180(data, imageWidth, imageHeight);
|
||||
case 270:
|
||||
return rotateCCW(data, imageWidth, imageHeight);
|
||||
default:
|
||||
// Should not happen
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate an image by 90 degrees CW.
|
||||
*
|
||||
* @param data the image data, in with the first width * height bytes being the luminance data.
|
||||
* @param imageWidth the width of the image
|
||||
* @param imageHeight the height of the image
|
||||
* @return the rotated bytes
|
||||
*/
|
||||
public static byte[] rotateCW(byte[] data, int imageWidth, int imageHeight) {
|
||||
// Adapted from http://stackoverflow.com/a/15775173
|
||||
// data may contain more than just y (u and v), but we are only interested in the y section.
|
||||
|
||||
byte[] yuv = new byte[imageWidth * imageHeight];
|
||||
int i = 0;
|
||||
for (int x = 0; x < imageWidth; x++) {
|
||||
for (int y = imageHeight - 1; y >= 0; y--) {
|
||||
yuv[i] = data[y * imageWidth + x];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return yuv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate an image by 180 degrees.
|
||||
*
|
||||
* @param data the image data, in with the first width * height bytes being the luminance data.
|
||||
* @param imageWidth the width of the image
|
||||
* @param imageHeight the height of the image
|
||||
* @return the rotated bytes
|
||||
*/
|
||||
public static byte[] rotate180(byte[] data, int imageWidth, int imageHeight) {
|
||||
int n = imageWidth * imageHeight;
|
||||
byte[] yuv = new byte[n];
|
||||
|
||||
int i = n - 1;
|
||||
for (int j = 0; j < n; j++) {
|
||||
yuv[i] = data[j];
|
||||
i--;
|
||||
}
|
||||
return yuv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate an image by 90 degrees CCW.
|
||||
*
|
||||
* @param data the image data, in with the first width * height bytes being the luminance data.
|
||||
* @param imageWidth the width of the image
|
||||
* @param imageHeight the height of the image
|
||||
* @return the rotated bytes
|
||||
*/
|
||||
public static byte[] rotateCCW(byte[] data, int imageWidth, int imageHeight) {
|
||||
int n = imageWidth * imageHeight;
|
||||
byte[] yuv = new byte[n];
|
||||
int i = n - 1;
|
||||
for (int x = 0; x < imageWidth; x++) {
|
||||
for (int y = imageHeight - 1; y >= 0; y--) {
|
||||
yuv[i] = data[y * imageWidth + x];
|
||||
i--;
|
||||
}
|
||||
}
|
||||
return yuv;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.journeyapps.barcodescanner;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
@@ -50,19 +49,20 @@ public class ViewfinderView extends View {
|
||||
|
||||
protected final Paint paint;
|
||||
protected Bitmap resultBitmap;
|
||||
protected final int maskColor;
|
||||
protected int maskColor;
|
||||
protected final int resultColor;
|
||||
protected final int laserColor;
|
||||
protected final int resultPointColor;
|
||||
protected boolean laserVisibility;
|
||||
protected int scannerAlpha;
|
||||
protected List<ResultPoint> possibleResultPoints;
|
||||
protected List<ResultPoint> lastPossibleResultPoints;
|
||||
protected CameraPreview cameraPreview;
|
||||
|
||||
// Cache the framingRect and previewFramingRect, so that we can still draw it after the preview
|
||||
// Cache the framingRect and previewSize, so that we can still draw it after the preview
|
||||
// stopped.
|
||||
protected Rect framingRect;
|
||||
protected Rect previewFramingRect;
|
||||
protected Size previewSize;
|
||||
|
||||
// This constructor is used when the class is built from an XML resource.
|
||||
public ViewfinderView(Context context, AttributeSet attrs) {
|
||||
@@ -73,7 +73,7 @@ public class ViewfinderView extends View {
|
||||
|
||||
Resources resources = getResources();
|
||||
|
||||
// Get setted attributes on view
|
||||
// Get set attributes on view
|
||||
TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.zxing_finder);
|
||||
|
||||
this.maskColor = attributes.getColor(R.styleable.zxing_finder_zxing_viewfinder_mask,
|
||||
@@ -84,12 +84,14 @@ public class ViewfinderView extends View {
|
||||
resources.getColor(R.color.zxing_viewfinder_laser));
|
||||
this.resultPointColor = attributes.getColor(R.styleable.zxing_finder_zxing_possible_result_points,
|
||||
resources.getColor(R.color.zxing_possible_result_points));
|
||||
this.laserVisibility = attributes.getBoolean(R.styleable.zxing_finder_zxing_viewfinder_laser_visibility,
|
||||
true);
|
||||
|
||||
attributes.recycle();
|
||||
|
||||
scannerAlpha = 0;
|
||||
possibleResultPoints = new ArrayList<>(5);
|
||||
lastPossibleResultPoints = null;
|
||||
possibleResultPoints = new ArrayList<>(MAX_RESULT_POINTS);
|
||||
lastPossibleResultPoints = new ArrayList<>(MAX_RESULT_POINTS);
|
||||
}
|
||||
|
||||
public void setCameraPreview(CameraPreview view) {
|
||||
@@ -115,35 +117,38 @@ public class ViewfinderView extends View {
|
||||
public void cameraError(Exception error) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cameraClosed() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void refreshSizes() {
|
||||
if(cameraPreview == null) {
|
||||
if (cameraPreview == null) {
|
||||
return;
|
||||
}
|
||||
Rect framingRect = cameraPreview.getFramingRect();
|
||||
Rect previewFramingRect = cameraPreview.getPreviewFramingRect();
|
||||
if(framingRect != null && previewFramingRect != null) {
|
||||
Size previewSize = cameraPreview.getPreviewSize();
|
||||
if (framingRect != null && previewSize != null) {
|
||||
this.framingRect = framingRect;
|
||||
this.previewFramingRect = previewFramingRect;
|
||||
this.previewSize = previewSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("DrawAllocation")
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
refreshSizes();
|
||||
if (framingRect == null || previewFramingRect == null) {
|
||||
if (framingRect == null || previewSize == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Rect frame = framingRect;
|
||||
Rect previewFrame = previewFramingRect;
|
||||
final Rect frame = framingRect;
|
||||
final Size previewSize = this.previewSize;
|
||||
|
||||
int width = canvas.getWidth();
|
||||
int height = canvas.getHeight();
|
||||
final int width = getWidth();
|
||||
final int height = getHeight();
|
||||
|
||||
// Draw the exterior (i.e. outside the framing rect) darkened
|
||||
paint.setColor(resultBitmap != null ? resultColor : maskColor);
|
||||
@@ -157,43 +162,52 @@ public class ViewfinderView extends View {
|
||||
paint.setAlpha(CURRENT_POINT_OPACITY);
|
||||
canvas.drawBitmap(resultBitmap, null, frame, paint);
|
||||
} else {
|
||||
// If wanted, draw a red "laser scanner" line through the middle to show decoding is active
|
||||
if (laserVisibility) {
|
||||
paint.setColor(laserColor);
|
||||
|
||||
// Draw a red "laser scanner" line through the middle to show decoding is active
|
||||
paint.setColor(laserColor);
|
||||
paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
|
||||
scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;
|
||||
int middle = frame.height() / 2 + frame.top;
|
||||
canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint);
|
||||
paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
|
||||
scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;
|
||||
|
||||
float scaleX = frame.width() / (float) previewFrame.width();
|
||||
float scaleY = frame.height() / (float) previewFrame.height();
|
||||
|
||||
List<ResultPoint> currentPossible = possibleResultPoints;
|
||||
List<ResultPoint> currentLast = lastPossibleResultPoints;
|
||||
int frameLeft = frame.left;
|
||||
int frameTop = frame.top;
|
||||
if (currentPossible.isEmpty()) {
|
||||
lastPossibleResultPoints = null;
|
||||
} else {
|
||||
possibleResultPoints = new ArrayList<>(5);
|
||||
lastPossibleResultPoints = currentPossible;
|
||||
paint.setAlpha(CURRENT_POINT_OPACITY);
|
||||
paint.setColor(resultPointColor);
|
||||
for (ResultPoint point : currentPossible) {
|
||||
canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX),
|
||||
frameTop + (int) (point.getY() * scaleY),
|
||||
POINT_SIZE, paint);
|
||||
}
|
||||
final int middle = frame.height() / 2 + frame.top;
|
||||
canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint);
|
||||
}
|
||||
if (currentLast != null) {
|
||||
|
||||
final float scaleX = this.getWidth() / (float) previewSize.width;
|
||||
final float scaleY = this.getHeight() / (float) previewSize.height;
|
||||
|
||||
// draw the last possible result points
|
||||
if (!lastPossibleResultPoints.isEmpty()) {
|
||||
paint.setAlpha(CURRENT_POINT_OPACITY / 2);
|
||||
paint.setColor(resultPointColor);
|
||||
float radius = POINT_SIZE / 2.0f;
|
||||
for (ResultPoint point : currentLast) {
|
||||
canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX),
|
||||
frameTop + (int) (point.getY() * scaleY),
|
||||
radius, paint);
|
||||
for (final ResultPoint point : lastPossibleResultPoints) {
|
||||
canvas.drawCircle(
|
||||
(int) (point.getX() * scaleX),
|
||||
(int) (point.getY() * scaleY),
|
||||
radius, paint
|
||||
);
|
||||
}
|
||||
lastPossibleResultPoints.clear();
|
||||
}
|
||||
|
||||
// draw current possible result points
|
||||
if (!possibleResultPoints.isEmpty()) {
|
||||
paint.setAlpha(CURRENT_POINT_OPACITY);
|
||||
paint.setColor(resultPointColor);
|
||||
for (final ResultPoint point : possibleResultPoints) {
|
||||
canvas.drawCircle(
|
||||
(int) (point.getX() * scaleX),
|
||||
(int) (point.getY() * scaleY),
|
||||
POINT_SIZE, paint
|
||||
);
|
||||
}
|
||||
|
||||
// swap and clear buffers
|
||||
final List<ResultPoint> temp = possibleResultPoints;
|
||||
possibleResultPoints = lastPossibleResultPoints;
|
||||
lastPossibleResultPoints = temp;
|
||||
possibleResultPoints.clear();
|
||||
}
|
||||
|
||||
// Request another update at the animation interval, but only repaint the laser line,
|
||||
@@ -231,13 +245,15 @@ public class ViewfinderView extends View {
|
||||
* @param point a point to draw, relative to the preview frame
|
||||
*/
|
||||
public void addPossibleResultPoint(ResultPoint point) {
|
||||
List<ResultPoint> points = possibleResultPoints;
|
||||
points.add(point);
|
||||
int size = points.size();
|
||||
if (size > MAX_RESULT_POINTS) {
|
||||
// trim it
|
||||
points.subList(0, size - MAX_RESULT_POINTS / 2).clear();
|
||||
}
|
||||
if (possibleResultPoints.size() < MAX_RESULT_POINTS)
|
||||
possibleResultPoints.add(point);
|
||||
}
|
||||
|
||||
public void setMaskColor(int maskColor) {
|
||||
this.maskColor = maskColor;
|
||||
}
|
||||
|
||||
public void setLaserVisibility(boolean visible) {
|
||||
this.laserVisibility = visible;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-8
@@ -64,12 +64,9 @@ public final class AutoFocusManager {
|
||||
private final Camera.AutoFocusCallback autoFocusCallback = new Camera.AutoFocusCallback() {
|
||||
@Override
|
||||
public void onAutoFocus(boolean success, Camera theCamera) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
focusing = false;
|
||||
autoFocusAgainLater();
|
||||
}
|
||||
handler.post(() -> {
|
||||
focusing = false;
|
||||
autoFocusAgainLater();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -83,7 +80,6 @@ public final class AutoFocusManager {
|
||||
start();
|
||||
}
|
||||
|
||||
|
||||
private synchronized void autoFocusAgainLater() {
|
||||
if (!stopped && !handler.hasMessages(MESSAGE_FOCUS)) {
|
||||
handler.sendMessageDelayed(handler.obtainMessage(MESSAGE_FOCUS), AUTO_FOCUS_INTERVAL_MS);
|
||||
@@ -135,5 +131,4 @@ public final class AutoFocusManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-2
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.android.camera;
|
||||
package com.journeyapps.barcodescanner.camera;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.graphics.Rect;
|
||||
@@ -363,5 +363,4 @@ public final class CameraConfigurationUtils {
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
||||
+35
-16
@@ -1,14 +1,12 @@
|
||||
package com.journeyapps.barcodescanner.camera;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
import com.google.zxing.client.android.R;
|
||||
import com.journeyapps.barcodescanner.Size;
|
||||
import com.journeyapps.barcodescanner.SourceData;
|
||||
import com.journeyapps.barcodescanner.Util;
|
||||
|
||||
/**
|
||||
@@ -26,6 +24,9 @@ public class CameraInstance {
|
||||
private Handler readyHandler;
|
||||
private DisplayConfiguration displayConfiguration;
|
||||
private boolean open = false;
|
||||
private boolean cameraClosed = true;
|
||||
private Handler mainHandler;
|
||||
|
||||
private CameraSettings cameraSettings = new CameraSettings();
|
||||
|
||||
/**
|
||||
@@ -41,6 +42,7 @@ public class CameraInstance {
|
||||
this.cameraThread = CameraThread.getInstance();
|
||||
this.cameraManager = new CameraManager(context);
|
||||
this.cameraManager.setCameraSettings(cameraSettings);
|
||||
this.mainHandler = new Handler();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +77,6 @@ public class CameraInstance {
|
||||
this.surface = surface;
|
||||
}
|
||||
|
||||
|
||||
public CameraSettings getCameraSettings() {
|
||||
return cameraSettings;
|
||||
}
|
||||
@@ -114,6 +115,7 @@ public class CameraInstance {
|
||||
Util.validateMainThread();
|
||||
|
||||
open = true;
|
||||
cameraClosed = false;
|
||||
|
||||
cameraThread.incrementAndEnqueue(opener);
|
||||
}
|
||||
@@ -136,12 +138,20 @@ public class CameraInstance {
|
||||
Util.validateMainThread();
|
||||
|
||||
if (open) {
|
||||
cameraThread.enqueue(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cameraManager.setTorch(on);
|
||||
}
|
||||
});
|
||||
cameraThread.enqueue(() -> cameraManager.setTorch(on));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the settings for Camera.
|
||||
*
|
||||
* @param callback {@link CameraParametersCallback}
|
||||
*/
|
||||
public void changeCameraParameters(final CameraParametersCallback callback) {
|
||||
Util.validateMainThread();
|
||||
|
||||
if (open) {
|
||||
cameraThread.enqueue(() -> cameraManager.changeCameraParameters(callback));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +160,8 @@ public class CameraInstance {
|
||||
|
||||
if (open) {
|
||||
cameraThread.enqueue(closer);
|
||||
} else {
|
||||
cameraClosed = true;
|
||||
}
|
||||
|
||||
open = false;
|
||||
@@ -159,14 +171,18 @@ public class CameraInstance {
|
||||
return open;
|
||||
}
|
||||
|
||||
public void requestPreview(final PreviewCallback callback) {
|
||||
validateOpen();
|
||||
public boolean isCameraClosed() {
|
||||
return cameraClosed;
|
||||
}
|
||||
|
||||
cameraThread.enqueue(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cameraManager.requestPreviewFrame(callback);
|
||||
public void requestPreview(final PreviewCallback callback) {
|
||||
mainHandler.post(() -> {
|
||||
if (!open) {
|
||||
Log.d(TAG, "Camera is closed, not requesting preview");
|
||||
return;
|
||||
}
|
||||
|
||||
cameraThread.enqueue(() -> cameraManager.requestPreviewFrame(callback));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -176,7 +192,6 @@ public class CameraInstance {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Runnable opener = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -231,6 +246,10 @@ public class CameraInstance {
|
||||
Log.e(TAG, "Failed to close camera", e);
|
||||
}
|
||||
|
||||
cameraClosed = true;
|
||||
|
||||
readyHandler.sendEmptyMessage(R.id.zxing_camera_closed);
|
||||
|
||||
cameraThread.decrementInstances();
|
||||
}
|
||||
};
|
||||
|
||||
+67
-33
@@ -16,19 +16,14 @@
|
||||
|
||||
package com.journeyapps.barcodescanner.camera;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
import com.google.zxing.client.android.AmbientLightManager;
|
||||
import com.google.zxing.client.android.camera.CameraConfigurationUtils;
|
||||
import com.google.zxing.client.android.camera.open.OpenCameraInterface;
|
||||
import com.journeyapps.barcodescanner.Size;
|
||||
import com.journeyapps.barcodescanner.SourceData;
|
||||
@@ -100,11 +95,30 @@ public final class CameraManager {
|
||||
Size cameraResolution = resolution;
|
||||
PreviewCallback callback = this.callback;
|
||||
if (cameraResolution != null && callback != null) {
|
||||
int format = camera.getParameters().getPreviewFormat();
|
||||
SourceData source = new SourceData(data, cameraResolution.width, cameraResolution.height, format, getCameraRotation());
|
||||
callback.onPreview(source);
|
||||
try {
|
||||
if (data == null) {
|
||||
throw new NullPointerException("No preview data received");
|
||||
}
|
||||
int format = camera.getParameters().getPreviewFormat();
|
||||
SourceData source = new SourceData(data, cameraResolution.width, cameraResolution.height, format, getCameraRotation());
|
||||
|
||||
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
|
||||
source.setPreviewMirrored(true);
|
||||
}
|
||||
callback.onPreview(source);
|
||||
} catch (RuntimeException e) {
|
||||
// Could be:
|
||||
// java.lang.RuntimeException: getParameters failed (empty parameters)
|
||||
// IllegalArgumentException: Image data does not match the resolution
|
||||
Log.e(TAG, "Camera preview failed", e);
|
||||
callback.onPreviewError(e);
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Got preview callback, but no handler or resolution available");
|
||||
if (callback != null) {
|
||||
// Should generally not happen
|
||||
callback.onPreviewError(new Exception("No resolution available"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,7 +156,7 @@ public final class CameraManager {
|
||||
* Must be called from camera thread.
|
||||
*/
|
||||
public void configure() {
|
||||
if(camera == null) {
|
||||
if (camera == null) {
|
||||
throw new RuntimeException("Camera not open");
|
||||
}
|
||||
setParameters();
|
||||
@@ -196,7 +210,6 @@ public final class CameraManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes the camera driver if still in use.
|
||||
*
|
||||
@@ -213,7 +226,7 @@ public final class CameraManager {
|
||||
* @return true if the camera rotation is perpendicular to the current display rotation.
|
||||
*/
|
||||
public boolean isCameraRotated() {
|
||||
if(rotationDegrees == -1) {
|
||||
if (rotationDegrees == -1) {
|
||||
throw new IllegalStateException("Rotation not calculated yet. Call configure() first.");
|
||||
}
|
||||
return rotationDegrees % 180 != 0;
|
||||
@@ -228,7 +241,6 @@ public final class CameraManager {
|
||||
return rotationDegrees;
|
||||
}
|
||||
|
||||
|
||||
private Camera.Parameters getDefaultCameraParameters() {
|
||||
Camera.Parameters parameters = camera.getParameters();
|
||||
if (defaultParameters == null) {
|
||||
@@ -254,7 +266,6 @@ public final class CameraManager {
|
||||
Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
|
||||
}
|
||||
|
||||
|
||||
CameraConfigurationUtils.setFocus(parameters, settings.getFocusMode(), safeMode);
|
||||
|
||||
if (!safeMode) {
|
||||
@@ -269,11 +280,9 @@ public final class CameraManager {
|
||||
}
|
||||
|
||||
if (settings.isMeteringEnabled()) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
|
||||
CameraConfigurationUtils.setVideoStabilization(parameters);
|
||||
CameraConfigurationUtils.setFocusArea(parameters);
|
||||
CameraConfigurationUtils.setMetering(parameters);
|
||||
}
|
||||
CameraConfigurationUtils.setVideoStabilization(parameters);
|
||||
CameraConfigurationUtils.setFocusArea(parameters);
|
||||
CameraConfigurationUtils.setMetering(parameters);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -304,7 +313,7 @@ public final class CameraManager {
|
||||
if (rawSupportedSizes == null) {
|
||||
Camera.Size defaultSize = parameters.getPreviewSize();
|
||||
if (defaultSize != null) {
|
||||
// Work around potential platform bugs
|
||||
Size previewSize = new Size(defaultSize.width, defaultSize.height);
|
||||
previewSizes.add(new Size(defaultSize.width, defaultSize.height));
|
||||
}
|
||||
return previewSizes;
|
||||
@@ -349,7 +358,6 @@ public final class CameraManager {
|
||||
camera.setDisplayOrientation(rotation);
|
||||
}
|
||||
|
||||
|
||||
private void setParameters() {
|
||||
try {
|
||||
this.rotationDegrees = calculateDisplayRotation();
|
||||
@@ -444,26 +452,52 @@ public final class CameraManager {
|
||||
|
||||
public void setTorch(boolean on) {
|
||||
if (camera != null) {
|
||||
boolean isOn = isTorchOn();
|
||||
if (on != isOn) {
|
||||
if (autoFocusManager != null) {
|
||||
autoFocusManager.stop();
|
||||
}
|
||||
try {
|
||||
boolean isOn = isTorchOn();
|
||||
if (on != isOn) {
|
||||
if (autoFocusManager != null) {
|
||||
autoFocusManager.stop();
|
||||
}
|
||||
|
||||
Camera.Parameters parameters = camera.getParameters();
|
||||
CameraConfigurationUtils.setTorch(parameters, on);
|
||||
if (settings.isExposureEnabled()) {
|
||||
CameraConfigurationUtils.setBestExposure(parameters, on);
|
||||
}
|
||||
camera.setParameters(parameters);
|
||||
Camera.Parameters parameters = camera.getParameters();
|
||||
CameraConfigurationUtils.setTorch(parameters, on);
|
||||
if (settings.isExposureEnabled()) {
|
||||
CameraConfigurationUtils.setBestExposure(parameters, on);
|
||||
}
|
||||
camera.setParameters(parameters);
|
||||
|
||||
if (autoFocusManager != null) {
|
||||
autoFocusManager.start();
|
||||
if (autoFocusManager != null) {
|
||||
autoFocusManager.start();
|
||||
}
|
||||
}
|
||||
} catch(RuntimeException e) {
|
||||
// Camera error. Could happen if the camera is being closed.
|
||||
Log.e(TAG, "Failed to set torch", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the settings for Camera.
|
||||
*
|
||||
* @param callback {@link CameraParametersCallback}
|
||||
*/
|
||||
public void changeCameraParameters(CameraParametersCallback callback) {
|
||||
if (camera != null) {
|
||||
try {
|
||||
camera.setParameters(callback.changeCameraParameters(camera.getParameters()));
|
||||
} catch(RuntimeException e) {
|
||||
// Camera error. Could happen if the camera is being closed.
|
||||
Log.e(TAG, "Failed to change camera parameters", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if the torch is on
|
||||
* @throws RuntimeException if there is a camera error
|
||||
*/
|
||||
public boolean isTorchOn() {
|
||||
Camera.Parameters parameters = camera.getParameters();
|
||||
if (parameters != null) {
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.journeyapps.barcodescanner.camera;
|
||||
|
||||
import android.hardware.Camera;
|
||||
|
||||
/**
|
||||
* Callback for {@link Camera.Parameters}.
|
||||
*/
|
||||
public interface CameraParametersCallback {
|
||||
|
||||
/**
|
||||
* Changes the settings for Camera.
|
||||
*
|
||||
* @param parameters {@link Camera.Parameters}.
|
||||
* @return {@link Camera.Parameters} with arguments.
|
||||
*/
|
||||
Camera.Parameters changeCameraParameters(Camera.Parameters parameters);
|
||||
}
|
||||
@@ -27,7 +27,6 @@ public class CameraSettings {
|
||||
return requestedCameraId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Allows third party apps to specify the camera ID, rather than determine
|
||||
* it automatically based on available cameras and their orientation.
|
||||
|
||||
@@ -17,14 +17,14 @@ public class CameraSurface {
|
||||
private SurfaceTexture surfaceTexture;
|
||||
|
||||
public CameraSurface(SurfaceHolder surfaceHolder) {
|
||||
if(surfaceHolder == null) {
|
||||
if (surfaceHolder == null) {
|
||||
throw new IllegalArgumentException("surfaceHolder may not be null");
|
||||
}
|
||||
this.surfaceHolder = surfaceHolder;
|
||||
}
|
||||
|
||||
public CameraSurface(SurfaceTexture surfaceTexture) {
|
||||
if(surfaceTexture == null) {
|
||||
if (surfaceTexture == null) {
|
||||
throw new IllegalArgumentException("surfaceTexture may not be null");
|
||||
}
|
||||
this.surfaceTexture = surfaceTexture;
|
||||
@@ -39,15 +39,10 @@ public class CameraSurface {
|
||||
}
|
||||
|
||||
public void setPreview(Camera camera) throws IOException {
|
||||
if(surfaceHolder != null) {
|
||||
if (surfaceHolder != null) {
|
||||
camera.setPreviewDisplay(surfaceHolder);
|
||||
} else {
|
||||
if(Build.VERSION.SDK_INT >= 11) {
|
||||
camera.setPreviewTexture(surfaceTexture);
|
||||
} else {
|
||||
// This should not happen, but we check for it anyway.
|
||||
throw new IllegalStateException("SurfaceTexture not supported.");
|
||||
}
|
||||
camera.setPreviewTexture(surfaceTexture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ class CameraThread {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private Handler handler;
|
||||
private HandlerThread thread;
|
||||
|
||||
@@ -100,7 +99,7 @@ class CameraThread {
|
||||
/**
|
||||
* Call from main thread.
|
||||
*
|
||||
* @param runner
|
||||
* @param runner The {@link Runnable} to be enqueued
|
||||
*/
|
||||
protected void incrementAndEnqueue(Runnable runner) {
|
||||
synchronized (LOCK) {
|
||||
|
||||
+2
-7
@@ -5,10 +5,6 @@ import android.util.Log;
|
||||
|
||||
import com.journeyapps.barcodescanner.Size;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Scales the dimensions so that it fits entirely inside the parent.One of width or height will
|
||||
* fit exactly. Aspect ratio is preserved.
|
||||
@@ -31,7 +27,7 @@ public class CenterCropStrategy extends PreviewScalingStrategy {
|
||||
*/
|
||||
@Override
|
||||
protected float getScore(Size size, Size desired) {
|
||||
if(size.width <= 0 || size.height <= 0) {
|
||||
if (size.width <= 0 || size.height <= 0) {
|
||||
return 0f;
|
||||
}
|
||||
Size scaled = size.scaleCrop(desired);
|
||||
@@ -40,7 +36,7 @@ public class CenterCropStrategy extends PreviewScalingStrategy {
|
||||
|
||||
// Treat downscaling as slightly better than upscaling
|
||||
float scaleScore;
|
||||
if(scaleRatio > 1.0f) {
|
||||
if (scaleRatio > 1.0f) {
|
||||
// Upscaling
|
||||
scaleScore = (float)Math.pow(1.0f / scaleRatio, 1.1);
|
||||
} else {
|
||||
@@ -79,5 +75,4 @@ public class CenterCropStrategy extends PreviewScalingStrategy {
|
||||
|
||||
return new Rect(-dx, -dy, scaledPreview.width - dx, scaledPreview.height - dy);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-7
@@ -5,10 +5,6 @@ import android.util.Log;
|
||||
|
||||
import com.journeyapps.barcodescanner.Size;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Scales the size so that both dimensions will be greater than or equal to the corresponding
|
||||
* dimension of the parent. One of width or height will fit exactly. Aspect ratio is preserved.
|
||||
@@ -31,7 +27,7 @@ public class FitCenterStrategy extends PreviewScalingStrategy {
|
||||
*/
|
||||
@Override
|
||||
protected float getScore(Size size, Size desired) {
|
||||
if(size.width <= 0 || size.height <= 0) {
|
||||
if (size.width <= 0 || size.height <= 0) {
|
||||
return 0f;
|
||||
}
|
||||
Size scaled = size.scaleFit(desired);
|
||||
@@ -40,7 +36,7 @@ public class FitCenterStrategy extends PreviewScalingStrategy {
|
||||
|
||||
// Treat downscaling as slightly better than upscaling
|
||||
float scaleScore;
|
||||
if(scaleRatio > 1.0f) {
|
||||
if (scaleRatio > 1.0f) {
|
||||
// Upscaling
|
||||
scaleScore = (float)Math.pow(1.0f / scaleRatio, 1.1);
|
||||
} else {
|
||||
@@ -79,5 +75,4 @@ public class FitCenterStrategy extends PreviewScalingStrategy {
|
||||
|
||||
return new Rect(-dx, -dy, scaledPreview.width - dx, scaledPreview.height - dy);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
package com.journeyapps.barcodescanner.camera;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.util.Log;
|
||||
|
||||
import com.journeyapps.barcodescanner.Size;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Scales the size so that it fits exactly. Aspect ratio is NOT preserved.
|
||||
*/
|
||||
@@ -17,7 +12,7 @@ public class FitXYStrategy extends PreviewScalingStrategy {
|
||||
|
||||
|
||||
private static float absRatio(float ratio) {
|
||||
if(ratio < 1.0f) {
|
||||
if (ratio < 1.0f) {
|
||||
return 1.0f / ratio;
|
||||
} else {
|
||||
return ratio;
|
||||
@@ -38,7 +33,7 @@ public class FitXYStrategy extends PreviewScalingStrategy {
|
||||
*/
|
||||
@Override
|
||||
protected float getScore(Size size, Size desired) {
|
||||
if(size.width <= 0 || size.height <= 0) {
|
||||
if (size.width <= 0 || size.height <= 0) {
|
||||
return 0f;
|
||||
}
|
||||
float scaleX = absRatio(size.width * 1.0f / desired.width);
|
||||
@@ -64,5 +59,4 @@ public class FitXYStrategy extends PreviewScalingStrategy {
|
||||
public Rect scalePreview(Size previewSize, Size viewfinderSize) {
|
||||
return new Rect(0, 0, viewfinderSize.width, viewfinderSize.height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-3
@@ -80,8 +80,6 @@ public class LegacyPreviewScalingStrategy extends PreviewScalingStrategy {
|
||||
return sizes.get(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Scale from so that to.fitsIn(size). Tries to scale by powers of two, or by 3/2. Aspect ratio
|
||||
* is preserved.
|
||||
@@ -154,5 +152,4 @@ public class LegacyPreviewScalingStrategy extends PreviewScalingStrategy {
|
||||
|
||||
return new Rect(-dx, -dy, scaledPreview.width - dx, scaledPreview.height - dy);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ import com.journeyapps.barcodescanner.SourceData;
|
||||
*/
|
||||
public interface PreviewCallback {
|
||||
void onPreview(SourceData sourceData);
|
||||
void onPreviewError(Exception e);
|
||||
}
|
||||
|
||||
-1
@@ -85,7 +85,6 @@ public abstract class PreviewScalingStrategy {
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scale and position the preview relative to the viewfinder.
|
||||
*
|
||||
|
||||
@@ -19,7 +19,6 @@ public class SizeTest {
|
||||
|
||||
assertEquals(12, a.width);
|
||||
assertEquals(9, a.height);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user