Skip to content

Commit

Permalink
Merge pull request #665 from journeyapps/fixes
Browse files Browse the repository at this point in the history
v4.3.0
  • Loading branch information
rkistner authored Oct 25, 2021
2 parents 4026027 + 6ccf3a9 commit 24d0294
Show file tree
Hide file tree
Showing 23 changed files with 798 additions and 364 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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*"
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

14 changes: 14 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
### 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).
Expand Down
125 changes: 67 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,61 @@ repositories {
}
dependencies {
implementation 'com.journeyapps:zxing-android-embedded:4.2.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
}
android {
buildToolsVersion '28.0.3' // Older versions may give compile errors
}
```

## Older SDK versions

For Android SDK versions < 24, you can downgrade `zxing:core` to 3.3.0 or earlier for Android 14+ support:
By default, only SDK 24+ is supported, even though the library specifies 19 as the minimum version.
No guarantees are made on support for SDK versions below 24 - you'll have to test to make sure it's compatible.

SDK versions 19 - 23 should also work, but one of the changes changes below are required,
and this is not routinely tested.

### Option 1. Downgrade zxing:core to 3.3.0

```groovy
repositories {
mavenCentral()
}
dependencies {
implementation('com.journeyapps:zxing-android-embedded:4.2.0') { transitive = false }
implementation 'androidx.appcompat:appcompat:1.0.2'
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.

See [Java 8+ API desugaring support](https://developer.android.com/studio/write/java8-support#library-desugaring).

```groovy
android {
buildToolsVersion '28.0.3'
}
defaultConfig {
// Important: multidex must be enabled
// https://developer.android.com/studio/build/multidex#mdex-gradle
multiDexEnabled true
minSdkVersion 19
}
```
You'll also need this in your Android manifest:
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
}
}
```xml
<uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
implementation "androidx.multidex:multidex:2.0.1"
}
```

No guarantees are made on support for older SDK versions - you'll have to test to make sure it's compatible.

## Hardware Acceleration

Hardware acceleration is required since TextureView is used.
Expand All @@ -75,48 +92,42 @@ Make sure it is enabled in your manifest file:
<application android:hardwareAccelerated="true" ... >
```

## Usage with IntentIntegrator
## Usage with ScanContract

Launch the intent with the default options:
```java
new IntentIntegrator(this).initiateScan(); // `this` is the current Activity


// 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);
}
}
```
Note: `startActivityForResult` is deprecated, so this example uses `registerForActivityResult` instead.
See for details: https://developer.android.com/training/basics/intents/result

Use from a Fragment:
```java
IntentIntegrator.forFragment(this).initiateScan(); // `this` is the current Fragment
`startActivityForResult` can still be used via `IntentIntegrator`, but that is not recommended anymore.

// If you're using the support library, use IntentIntegrator.forSupportFragment(this) instead.
```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

Expand Down Expand Up @@ -152,9 +163,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
Expand Down Expand Up @@ -198,7 +209,7 @@ You can then use your local version by specifying in your `build.gradle` file:

Licensed under the [Apache License 2.0][7]

Copyright (C) 2012-2018 ZXing authors, Journey Mobile
Copyright (C) 2012-201 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.
Expand All @@ -216,7 +227,5 @@ Licensed under the [Apache License 2.0][7]

[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
20 changes: 4 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ buildscript {
repositories {
google()
mavenCentral()
jcenter {
content {
// https://youtrack.jetbrains.com/issue/IDEA-261387
includeModule("org.jetbrains.trove4j", "trove4j")
}
}
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:7.0.3'
}
}

Expand All @@ -20,17 +14,11 @@ subprojects {
google()
mavenLocal()
mavenCentral()
jcenter {
content {
// https://youtrack.jetbrains.com/issue/IDEA-261387
includeModule("org.jetbrains.trove4j", "trove4j")
}
}
}

version = '4.2.0'
version = '4.3.0'
group = 'com.journeyapps'

ext.androidTargetSdk = 28
ext.zxingCore = 'com.google.zxing:core:3.4.0'
ext.androidTargetSdk = 30
ext.zxingCore = 'com.google.zxing:core:3.4.1'
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
android.enableJetifier=true
android.enableJetifier=false
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Sat Sep 07 15:17:02 SAST 2019
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-6.0-all.zip
Loading

0 comments on commit 24d0294

Please sign in to comment.