Compare commits

...

12 Commits

Author SHA1 Message Date
Ralf Kistner d09b7c76c3 Merge pull request #726 from yuchan2215/patch-1
Fix Typo
2022-10-21 10:40:04 +02:00
yuchan2215 3a2db7ffc6 Fix Typo 2022-10-21 12:04:14 +09:00
Ralf Kistner 2a65a6c973 Merge pull request #708 from amirrudd/patch-1
Remove duplicate in ReadMe
2022-06-16 15:14:09 +02:00
Amir Rudd 3c77f1d6c8 Remove duplicate in ReadMe 2022-06-16 15:24:55 +04:30
Ralf Kistner b6c6421dd5 Merge pull request #696 from saifkhichi96/patch-1
Added ability to customize colors in barcodes generated with BarcodeEncoder.
2022-02-21 09:58:04 +02:00
Muhammad Saif Ullah Khan 8173d4a8b2 Added color customization instructions in README 2022-02-08 18:27:41 +01:00
Muhammad Saif Ullah Khan 8fdbbbef5e Support custom colors in BarcodeEncoder.java. 2022-02-08 18:17:58 +01:00
Conrad Hofmeyr 2324a5403e Update README.md 2021-12-22 12:29:22 -07:00
Ralf Kistner c752130405 Merge pull request #673 from juliansteenbakker/make-initializeAttributes-public
imp: make initializeAttributes public
2021-11-17 10:32:59 +02:00
juliansteenbakker 1c27c8fe2d imp: make initializeAttributes public 2021-11-17 08:52:37 +01:00
Ralf Kistner aa129af542 Merge pull request #666 from journeyapps/update-readme-sdk-version
Update notes on minSdkVersion
2021-10-26 16:19:21 +02:00
Ralf Kistner 90b5db5fcd Update notes on minSdkVersion. 2021-10-26 10:49:40 +02:00
3 changed files with 58 additions and 19 deletions
+46 -15
View File
@@ -13,15 +13,16 @@ 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.0. To support SDK 14+, see [Older SDK versions](#older-sdk-versions).
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 4.x, only Android SDK 24+ is supported by default, and androidx is required.
Add the following to your `build.gradle` file:
```groovy
// Config for SDK 24+
repositories {
mavenCentral()
}
@@ -33,11 +34,10 @@ dependencies {
## Older SDK versions
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.
By default, only SDK 24+ will work, even though the library specifies 19 as the minimum version.
SDK versions 19 - 23 should also work, but one of the changes changes below are required,
and this is not routinely tested.
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.
### Option 1. Downgrade zxing:core to 3.3.0
@@ -56,13 +56,40 @@ dependencies {
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'
}
```
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).
```groovy
android {
defaultConfig {
// Important: multidex must be enabled
// https://developer.android.com/studio/build/multidex#mdex-gradle
multiDexEnabled true
minSdkVersion 19
}
@@ -77,6 +104,8 @@ android {
}
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"
}
@@ -143,12 +172,14 @@ try {
} catch(Exception e) {
}
No customization of the image is currently supported, including changing colors or padding. If you
require more customization, copy and modify the source for the encoder.
```
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
To change the orientation, specify the orientation in your `AndroidManifest.xml` and let the `ManifestMerger` to update the Activity's definition.
@@ -202,14 +233,14 @@ 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
Licensed under the [Apache License 2.0][7]
Copyright (C) 2012-201 ZXing authors, Journey Mobile
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.
@@ -19,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();
@@ -33,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;
}
}
@@ -266,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);