Runnables that have already started to execute will continue.
58 | */
59 | public void shutdown() {
60 | shutdown.set(true);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/barcode/src/main/java/com/kathline/barcode/VisionImageProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Google LLC. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.kathline.barcode;
18 |
19 | import android.graphics.Bitmap;
20 |
21 | import com.google.mlkit.common.MlKitException;
22 |
23 | import java.nio.ByteBuffer;
24 |
25 | /** An interface to process the images with different vision detectors and custom image models. */
26 | public interface VisionImageProcessor {
27 |
28 | /** Processes a bitmap image. */
29 | void processBitmap(Bitmap bitmap, GraphicOverlay graphicOverlay);
30 |
31 | /** Processes ByteBuffer image data, e.g. used for Camera1 live preview case. */
32 | void processByteBuffer(
33 | ByteBuffer data, FrameMetadata frameMetadata, GraphicOverlay graphicOverlay)
34 | throws MlKitException;
35 |
36 | /** Stops the underlying machine learning model and release resources. */
37 | void stop();
38 | }
39 |
--------------------------------------------------------------------------------
/barcode/src/main/java/com/kathline/barcode/hardware/FrontLightMode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.kathline.barcode.hardware;
18 |
19 | /**
20 | * Enumerates settings of the preference controlling the front light.
21 | */
22 | public enum FrontLightMode {
23 |
24 | /** Always on. */
25 | ON,
26 | /** On only when ambient light is low. */
27 | AUTO,
28 | /** Always off. */
29 | OFF;
30 |
31 | private static FrontLightMode parse(String modeString) {
32 | return modeString == null ? OFF : valueOf(modeString);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/barcode/src/main/res/drawable/ic_switch_camera_white_48dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/barcode/src/main/res/drawable/toggle_style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/barcode/src/main/res/layout/settings_style.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
--------------------------------------------------------------------------------
/barcode/src/main/res/mipmap-xhdpi/ic_settings_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DyncKathline/ZxingScan/e87cd33c33d6a2d3779498a80e7ee33cebad28aa/barcode/src/main/res/mipmap-xhdpi/ic_settings_white_24dp.png
--------------------------------------------------------------------------------
/barcode/src/main/res/mipmap-xhdpi/ic_switch_camera_white_48dp_inset.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DyncKathline/ZxingScan/e87cd33c33d6a2d3779498a80e7ee33cebad28aa/barcode/src/main/res/mipmap-xhdpi/ic_switch_camera_white_48dp_inset.png
--------------------------------------------------------------------------------
/barcode/src/main/res/mipmap-xhdpi/ico_wechat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DyncKathline/ZxingScan/e87cd33c33d6a2d3779498a80e7ee33cebad28aa/barcode/src/main/res/mipmap-xhdpi/ico_wechat.png
--------------------------------------------------------------------------------
/barcode/src/main/res/raw/beep.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DyncKathline/ZxingScan/e87cd33c33d6a2d3779498a80e7ee33cebad28aa/barcode/src/main/res/raw/beep.ogg
--------------------------------------------------------------------------------
/barcode/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/barcode/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #60000000
5 | #7F1FB3E2
6 | #FF1FB3E2
7 | #FF1FB3E2
8 | #FFC0C0C0
9 |
10 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.6.3'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
12 |
13 |
14 | // NOTE: Do not place your application dependencies here; they belong
15 | // in the individual module build.gradle files
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | google()
22 | jcenter()
23 | mavenCentral()
24 | maven { url "https://maven.aliyun.com/repository/public" } //jcenter & central
25 | maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" }
26 | // maven { url "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" }
27 | maven { url "https://jitpack.io" }
28 | }
29 | }
30 |
31 | task clean(type: Delete) {
32 | delete rootProject.buildDir
33 | }
34 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
19 | android.useAndroidX=true
20 | # Automatically convert third-party libraries to use AndroidX
21 | android.enableJetifier=true
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu May 23 22:41:35 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/screenshot/GIF1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DyncKathline/ZxingScan/e87cd33c33d6a2d3779498a80e7ee33cebad28aa/screenshot/GIF1.gif
--------------------------------------------------------------------------------
/screenshot/GIF2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DyncKathline/ZxingScan/e87cd33c33d6a2d3779498a80e7ee33cebad28aa/screenshot/GIF2.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':barcode'
2 | include ':app', ':zxinglibrary'
3 |
--------------------------------------------------------------------------------
/zxinglibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/zxinglibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 30
5 | // buildToolsVersion "30.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 19
9 | targetSdkVersion 30
10 | versionCode 9
11 | versionName "4.0.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 |
29 | implementation 'androidx.appcompat:appcompat:1.2.0'
30 | // implementation 'com.google.zxing:core:3.3.3'
31 | }
32 |
33 | ext {
34 | PUBLISH_GROUP_ID = "com.github.dynckathline"
35 | PUBLISH_ARTIFACT_ID = "zxinglibrary"
36 | PUBLISH_VERSION = android.defaultConfig.versionName
37 | }
38 | apply from: "${rootProject.projectDir}/mavencentral.gradle"
--------------------------------------------------------------------------------
/zxinglibrary/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
16 |
17 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/BarcodeFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing;
18 |
19 | /**
20 | * Enumerates barcode formats known to this package. Please keep alphabetized.
21 | *
22 | * @author Sean Owen
23 | */
24 | public enum BarcodeFormat {
25 |
26 | /** Aztec 2D barcode format. */
27 | AZTEC,
28 |
29 | /** CODABAR 1D format. */
30 | CODABAR,
31 |
32 | /** Code 39 1D format. */
33 | CODE_39,
34 |
35 | /** Code 93 1D format. */
36 | CODE_93,
37 |
38 | /** Code 128 1D format. */
39 | CODE_128,
40 |
41 | /** Data Matrix 2D barcode format. */
42 | DATA_MATRIX,
43 |
44 | /** EAN-8 1D format. */
45 | EAN_8,
46 |
47 | /** EAN-13 1D format. */
48 | EAN_13,
49 |
50 | /** ITF (Interleaved Two of Five) 1D format. */
51 | ITF,
52 |
53 | /** MaxiCode 2D barcode format. */
54 | MAXICODE,
55 |
56 | /** PDF417 format. */
57 | PDF_417,
58 |
59 | /** QR Code 2D barcode format. */
60 | QR_CODE,
61 |
62 | /** RSS 14 */
63 | RSS_14,
64 |
65 | /** RSS EXPANDED */
66 | RSS_EXPANDED,
67 |
68 | /** UPC-A 1D format. */
69 | UPC_A,
70 |
71 | /** UPC-E 1D format. */
72 | UPC_E,
73 |
74 | /** UPC/EAN extension format. Not a stand-alone format. */
75 | UPC_EAN_EXTENSION
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/ChecksumException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing;
18 |
19 | /**
20 | * Thrown when a barcode was successfully detected and decoded, but
21 | * was not returned because its checksum feature failed.
22 | *
23 | * @author Sean Owen
24 | */
25 | public final class ChecksumException extends ReaderException {
26 |
27 | private static final ChecksumException INSTANCE = new ChecksumException();
28 | static {
29 | INSTANCE.setStackTrace(NO_TRACE); // since it's meaningless
30 | }
31 |
32 | private ChecksumException() {
33 | // do nothing
34 | }
35 |
36 | private ChecksumException(Throwable cause) {
37 | super(cause);
38 | }
39 |
40 | public static ChecksumException getChecksumInstance() {
41 | return isStackTrace ? new ChecksumException() : INSTANCE;
42 | }
43 |
44 | public static ChecksumException getChecksumInstance(Throwable cause) {
45 | return isStackTrace ? new ChecksumException(cause) : INSTANCE;
46 | }
47 | }
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/Dimension.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing;
18 |
19 | /**
20 | * Simply encapsulates a width and height.
21 | */
22 | public final class Dimension {
23 |
24 | private final int width;
25 | private final int height;
26 |
27 | public Dimension(int width, int height) {
28 | if (width < 0 || height < 0) {
29 | throw new IllegalArgumentException();
30 | }
31 | this.width = width;
32 | this.height = height;
33 | }
34 |
35 | public int getWidth() {
36 | return width;
37 | }
38 |
39 | public int getHeight() {
40 | return height;
41 | }
42 |
43 | @Override
44 | public boolean equals(Object other) {
45 | if (other instanceof Dimension) {
46 | Dimension d = (Dimension) other;
47 | return width == d.width && height == d.height;
48 | }
49 | return false;
50 | }
51 |
52 | @Override
53 | public int hashCode() {
54 | return width * 32713 + height;
55 | }
56 |
57 | @Override
58 | public String toString() {
59 | return width + "x" + height;
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/FormatException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing;
18 |
19 | /**
20 | * Thrown when a barcode was successfully detected, but some aspect of
21 | * the content did not conform to the barcode's format rules. This could have
22 | * been due to a mis-detection.
23 | *
24 | * @author Sean Owen
25 | */
26 | public final class FormatException extends ReaderException {
27 |
28 | private static final FormatException INSTANCE = new FormatException();
29 | static {
30 | INSTANCE.setStackTrace(NO_TRACE); // since it's meaningless
31 | }
32 |
33 | private FormatException() {
34 | }
35 |
36 | private FormatException(Throwable cause) {
37 | super(cause);
38 | }
39 |
40 | public static FormatException getFormatInstance() {
41 | return isStackTrace ? new FormatException() : INSTANCE;
42 | }
43 |
44 | public static FormatException getFormatInstance(Throwable cause) {
45 | return isStackTrace ? new FormatException(cause) : INSTANCE;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/InvertedLuminanceSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing;
18 |
19 | /**
20 | * A wrapper implementation of {@link LuminanceSource} which inverts the luminances it returns -- black becomes
21 | * white and vice versa, and each value becomes (255-value).
22 | *
23 | * @author Sean Owen
24 | */
25 | public final class InvertedLuminanceSource extends LuminanceSource {
26 |
27 | private final LuminanceSource delegate;
28 |
29 | public InvertedLuminanceSource(LuminanceSource delegate) {
30 | super(delegate.getWidth(), delegate.getHeight());
31 | this.delegate = delegate;
32 | }
33 |
34 | @Override
35 | public byte[] getRow(int y, byte[] row) {
36 | row = delegate.getRow(y, row);
37 | int width = getWidth();
38 | for (int i = 0; i < width; i++) {
39 | row[i] = (byte) (255 - (row[i] & 0xFF));
40 | }
41 | return row;
42 | }
43 |
44 | @Override
45 | public byte[] getMatrix() {
46 | byte[] matrix = delegate.getMatrix();
47 | int length = getWidth() * getHeight();
48 | byte[] invertedMatrix = new byte[length];
49 | for (int i = 0; i < length; i++) {
50 | invertedMatrix[i] = (byte) (255 - (matrix[i] & 0xFF));
51 | }
52 | return invertedMatrix;
53 | }
54 |
55 | @Override
56 | public boolean isCropSupported() {
57 | return delegate.isCropSupported();
58 | }
59 |
60 | @Override
61 | public LuminanceSource crop(int left, int top, int width, int height) {
62 | return new InvertedLuminanceSource(delegate.crop(left, top, width, height));
63 | }
64 |
65 | @Override
66 | public boolean isRotateSupported() {
67 | return delegate.isRotateSupported();
68 | }
69 |
70 | /**
71 | * @return original delegate {@link LuminanceSource} since invert undoes itself
72 | */
73 | @Override
74 | public LuminanceSource invert() {
75 | return delegate;
76 | }
77 |
78 | @Override
79 | public LuminanceSource rotateCounterClockwise() {
80 | return new InvertedLuminanceSource(delegate.rotateCounterClockwise());
81 | }
82 |
83 | @Override
84 | public LuminanceSource rotateCounterClockwise45() {
85 | return new InvertedLuminanceSource(delegate.rotateCounterClockwise45());
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/NotFoundException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing;
18 |
19 | /**
20 | * Thrown when a barcode was not found in the image. It might have been
21 | * partially detected but could not be confirmed.
22 | *
23 | * @author Sean Owen
24 | */
25 | public final class NotFoundException extends ReaderException {
26 |
27 | private static final NotFoundException INSTANCE = new NotFoundException();
28 | static {
29 | INSTANCE.setStackTrace(NO_TRACE); // since it's meaningless
30 | }
31 |
32 | private NotFoundException() {
33 | // do nothing
34 | }
35 |
36 | public static NotFoundException getNotFoundInstance() {
37 | return INSTANCE;
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/ReaderException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing;
18 |
19 | /**
20 | * The general exception class throw when something goes wrong during decoding of a barcode.
21 | * This includes, but is not limited to, failing checksums / error correction algorithms, being
22 | * unable to locate finder timing patterns, and so on.
23 | *
24 | * @author Sean Owen
25 | */
26 | public abstract class ReaderException extends Exception {
27 |
28 | // disable stack traces when not running inside test units
29 | protected static final boolean isStackTrace =
30 | System.getProperty("surefire.test.class.path") != null;
31 | protected static final StackTraceElement[] NO_TRACE = new StackTraceElement[0];
32 |
33 | ReaderException() {
34 | // do nothing
35 | }
36 |
37 | ReaderException(Throwable cause) {
38 | super(cause);
39 | }
40 |
41 | // Prevent stack traces from being taken
42 | @Override
43 | public final synchronized Throwable fillInStackTrace() {
44 | return null;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/ResultPointCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing;
18 |
19 | /**
20 | * Callback which is invoked when a possible result point (significant
21 | * point in the barcode image such as a corner) is found.
22 | *
23 | * @see DecodeHintType#NEED_RESULT_POINT_CALLBACK
24 | */
25 | public interface ResultPointCallback {
26 |
27 | void foundPossibleResultPoint(ResultPoint point);
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/Writer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing;
18 |
19 | import com.google.zxing.common.BitMatrix;
20 |
21 | import java.util.Map;
22 |
23 | /**
24 | * The base class for all objects which encode/generate a barcode image.
25 | *
26 | * @author dswitkin@google.com (Daniel Switkin)
27 | */
28 | public interface Writer {
29 |
30 | /**
31 | * Encode a barcode using the default settings.
32 | *
33 | * @param contents The contents to encode in the barcode
34 | * @param format The barcode format to generate
35 | * @param width The preferred width in pixels
36 | * @param height The preferred height in pixels
37 | * @return {@link BitMatrix} representing encoded barcode image
38 | * @throws WriterException if contents cannot be encoded legally in a format
39 | */
40 | BitMatrix encode(String contents, BarcodeFormat format, int width, int height)
41 | throws WriterException;
42 |
43 | /**
44 | * @param contents The contents to encode in the barcode
45 | * @param format The barcode format to generate
46 | * @param width The preferred width in pixels
47 | * @param height The preferred height in pixels
48 | * @param hints Additional parameters to supply to the encoder
49 | * @return {@link BitMatrix} representing encoded barcode image
50 | * @throws WriterException if contents cannot be encoded legally in a format
51 | */
52 | BitMatrix encode(String contents,
53 | BarcodeFormat format,
54 | int width,
55 | int height,
56 | Map hints)
57 | throws WriterException;
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/WriterException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing;
18 |
19 | /**
20 | * A base class which covers the range of exceptions which may occur when encoding a barcode using
21 | * the Writer framework.
22 | *
23 | * @author dswitkin@google.com (Daniel Switkin)
24 | */
25 | public final class WriterException extends Exception {
26 |
27 | public WriterException() {
28 | }
29 |
30 | public WriterException(String message) {
31 | super(message);
32 | }
33 |
34 | public WriterException(Throwable cause) {
35 | super(cause);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/aztec/AztecDetectorResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.aztec;
18 |
19 | import com.google.zxing.ResultPoint;
20 | import com.google.zxing.common.BitMatrix;
21 | import com.google.zxing.common.DetectorResult;
22 |
23 | /**
24 | *
Extends {@link DetectorResult} with more information specific to the Aztec format,
25 | * like the number of layers and whether it's compact.
26 | *
27 | * @author Sean Owen
28 | */
29 | public final class AztecDetectorResult extends DetectorResult {
30 |
31 | private final boolean compact;
32 | private final int nbDatablocks;
33 | private final int nbLayers;
34 |
35 | public AztecDetectorResult(BitMatrix bits,
36 | ResultPoint[] points,
37 | boolean compact,
38 | int nbDatablocks,
39 | int nbLayers) {
40 | super(bits, points);
41 | this.compact = compact;
42 | this.nbDatablocks = nbDatablocks;
43 | this.nbLayers = nbLayers;
44 | }
45 |
46 | public int getNbLayers() {
47 | return nbLayers;
48 | }
49 |
50 | public int getNbDatablocks() {
51 | return nbDatablocks;
52 | }
53 |
54 | public boolean isCompact() {
55 | return compact;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/aztec/encoder/AztecCode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.aztec.encoder;
18 |
19 | import com.google.zxing.common.BitMatrix;
20 |
21 | /**
22 | * Aztec 2D code representation
23 | *
24 | * @author Rustam Abdullaev
25 | */
26 | public final class AztecCode {
27 |
28 | private boolean compact;
29 | private int size;
30 | private int layers;
31 | private int codeWords;
32 | private BitMatrix matrix;
33 |
34 | /**
35 | * @return {@code true} if compact instead of full mode
36 | */
37 | public boolean isCompact() {
38 | return compact;
39 | }
40 |
41 | public void setCompact(boolean compact) {
42 | this.compact = compact;
43 | }
44 |
45 | /**
46 | * @return size in pixels (width and height)
47 | */
48 | public int getSize() {
49 | return size;
50 | }
51 |
52 | public void setSize(int size) {
53 | this.size = size;
54 | }
55 |
56 | /**
57 | * @return number of levels
58 | */
59 | public int getLayers() {
60 | return layers;
61 | }
62 |
63 | public void setLayers(int layers) {
64 | this.layers = layers;
65 | }
66 |
67 | /**
68 | * @return number of data codewords
69 | */
70 | public int getCodeWords() {
71 | return codeWords;
72 | }
73 |
74 | public void setCodeWords(int codeWords) {
75 | this.codeWords = codeWords;
76 | }
77 |
78 | /**
79 | * @return the symbol image
80 | */
81 | public BitMatrix getMatrix() {
82 | return matrix;
83 | }
84 |
85 | public void setMatrix(BitMatrix matrix) {
86 | this.matrix = matrix;
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/aztec/encoder/BinaryShiftToken.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.aztec.encoder;
18 |
19 | import com.google.zxing.common.BitArray;
20 |
21 | final class BinaryShiftToken extends Token {
22 |
23 | private final short binaryShiftStart;
24 | private final short binaryShiftByteCount;
25 |
26 | BinaryShiftToken(Token previous,
27 | int binaryShiftStart,
28 | int binaryShiftByteCount) {
29 | super(previous);
30 | this.binaryShiftStart = (short) binaryShiftStart;
31 | this.binaryShiftByteCount = (short) binaryShiftByteCount;
32 | }
33 |
34 | @Override
35 | public void appendTo(BitArray bitArray, byte[] text) {
36 | for (int i = 0; i < binaryShiftByteCount; i++) {
37 | if (i == 0 || (i == 31 && binaryShiftByteCount <= 62)) {
38 | // We need a header before the first character, and before
39 | // character 31 when the total byte code is <= 62
40 | bitArray.appendBits(31, 5); // BINARY_SHIFT
41 | if (binaryShiftByteCount > 62) {
42 | bitArray.appendBits(binaryShiftByteCount - 31, 16);
43 | } else if (i == 0) {
44 | // 1 <= binaryShiftByteCode <= 62
45 | bitArray.appendBits(Math.min(binaryShiftByteCount, 31), 5);
46 | } else {
47 | // 32 <= binaryShiftCount <= 62 and i == 31
48 | bitArray.appendBits(binaryShiftByteCount - 31, 5);
49 | }
50 | }
51 | bitArray.appendBits(text[binaryShiftStart + i], 8);
52 | }
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return "<" + binaryShiftStart + "::" + (binaryShiftStart + binaryShiftByteCount - 1) + '>';
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/aztec/encoder/SimpleToken.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.aztec.encoder;
18 |
19 | import com.google.zxing.common.BitArray;
20 |
21 | final class SimpleToken extends Token {
22 |
23 | // For normal words, indicates value and bitCount
24 | private final short value;
25 | private final short bitCount;
26 |
27 | SimpleToken(Token previous, int value, int bitCount) {
28 | super(previous);
29 | this.value = (short) value;
30 | this.bitCount = (short) bitCount;
31 | }
32 |
33 | @Override
34 | void appendTo(BitArray bitArray, byte[] text) {
35 | bitArray.appendBits(value, bitCount);
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | int value = this.value & ((1 << bitCount) - 1);
41 | value |= 1 << bitCount;
42 | return '<' + Integer.toBinaryString(value | (1 << bitCount)).substring(1) + '>';
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/aztec/encoder/Token.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.aztec.encoder;
18 |
19 | import com.google.zxing.common.BitArray;
20 |
21 | abstract class Token {
22 |
23 | static final Token EMPTY = new SimpleToken(null, 0, 0);
24 |
25 | private final Token previous;
26 |
27 | Token(Token previous) {
28 | this.previous = previous;
29 | }
30 |
31 | final Token getPrevious() {
32 | return previous;
33 | }
34 |
35 | final Token add(int value, int bitCount) {
36 | return new SimpleToken(this, value, bitCount);
37 | }
38 |
39 | final Token addBinaryShift(int start, int byteCount) {
40 | //int bitCount = (byteCount * 8) + (byteCount <= 31 ? 10 : byteCount <= 62 ? 20 : 21);
41 | return new BinaryShiftToken(this, start, byteCount);
42 | }
43 |
44 | abstract void appendTo(BitArray bitArray, byte[] text);
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/common/DetectorResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.common;
18 |
19 | import com.google.zxing.ResultPoint;
20 |
21 | /**
22 | *
Encapsulates the result of detecting a barcode in an image. This includes the raw
23 | * matrix of black/white pixels corresponding to the barcode, and possibly points of interest
24 | * in the image, like the location of finder patterns or corners of the barcode in the image.
25 | *
26 | * @author Sean Owen
27 | */
28 | public class DetectorResult {
29 |
30 | private final BitMatrix bits;
31 | private final ResultPoint[] points;
32 |
33 | public DetectorResult(BitMatrix bits, ResultPoint[] points) {
34 | this.bits = bits;
35 | this.points = points;
36 | }
37 |
38 | public final BitMatrix getBits() {
39 | return bits;
40 | }
41 |
42 | public final ResultPoint[] getPoints() {
43 | return points;
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/common/detector/MathUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.common.detector;
18 |
19 | /**
20 | * General math-related and numeric utility functions.
21 | */
22 | public final class MathUtils {
23 |
24 | private MathUtils() {
25 | }
26 |
27 | /**
28 | * Ends up being a bit faster than {@link Math#round(float)}. This merely rounds its
29 | * argument to the nearest int, where x.5 rounds up to x+1. Semantics of this shortcut
30 | * differ slightly from {@link Math#round(float)} in that half rounds down for negative
31 | * values. -2.5 rounds to -3, not -2. For purposes here it makes no difference.
32 | *
33 | * @param d real value to round
34 | * @return nearest {@code int}
35 | */
36 | public static int round(float d) {
37 | return (int) (d + (d < 0.0f ? -0.5f : 0.5f));
38 | }
39 |
40 | /**
41 | * @param aX point A x coordinate
42 | * @param aY point A y coordinate
43 | * @param bX point B x coordinate
44 | * @param bY point B y coordinate
45 | * @return Euclidean distance between points A and B
46 | */
47 | public static float distance(float aX, float aY, float bX, float bY) {
48 | double xDiff = aX - bX;
49 | double yDiff = aY - bY;
50 | return (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff);
51 | }
52 |
53 | /**
54 | * @param aX point A x coordinate
55 | * @param aY point A y coordinate
56 | * @param bX point B x coordinate
57 | * @param bY point B y coordinate
58 | * @return Euclidean distance between points A and B
59 | */
60 | public static float distance(int aX, int aY, int bX, int bY) {
61 | double xDiff = aX - bX;
62 | double yDiff = aY - bY;
63 | return (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff);
64 | }
65 |
66 | /**
67 | * @param array values to sum
68 | * @return sum of values in array
69 | */
70 | public static int sum(int[] array) {
71 | int count = 0;
72 | for (int a : array) {
73 | count += a;
74 | }
75 | return count;
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/common/reedsolomon/ReedSolomonException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.common.reedsolomon;
18 |
19 | /**
20 | *
Thrown when an exception occurs during Reed-Solomon decoding, such as when
21 | * there are too many errors to correct.
22 | *
23 | * @author Sean Owen
24 | */
25 | public final class ReedSolomonException extends Exception {
26 |
27 | public ReedSolomonException(String message) {
28 | super(message);
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/datamatrix/encoder/Base256Encoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2006-2007 Jeremias Maerki.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.datamatrix.encoder;
18 |
19 | final class Base256Encoder implements Encoder {
20 |
21 | @Override
22 | public int getEncodingMode() {
23 | return HighLevelEncoder.BASE256_ENCODATION;
24 | }
25 |
26 | @Override
27 | public void encode(EncoderContext context) {
28 | StringBuilder buffer = new StringBuilder();
29 | buffer.append('\0'); //Initialize length field
30 | while (context.hasMoreCharacters()) {
31 | char c = context.getCurrentChar();
32 | buffer.append(c);
33 |
34 | context.pos++;
35 |
36 | int newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, getEncodingMode());
37 | if (newMode != getEncodingMode()) {
38 | // Return to ASCII encodation, which will actually handle latch to new mode
39 | context.signalEncoderChange(HighLevelEncoder.ASCII_ENCODATION);
40 | break;
41 | }
42 | }
43 | int dataCount = buffer.length() - 1;
44 | int lengthFieldSize = 1;
45 | int currentSize = context.getCodewordCount() + dataCount + lengthFieldSize;
46 | context.updateSymbolInfo(currentSize);
47 | boolean mustPad = (context.getSymbolInfo().getDataCapacity() - currentSize) > 0;
48 | if (context.hasMoreCharacters() || mustPad) {
49 | if (dataCount <= 249) {
50 | buffer.setCharAt(0, (char) dataCount);
51 | } else if (dataCount <= 1555) {
52 | buffer.setCharAt(0, (char) ((dataCount / 250) + 249));
53 | buffer.insert(1, (char) (dataCount % 250));
54 | } else {
55 | throw new IllegalStateException(
56 | "Message length not in valid ranges: " + dataCount);
57 | }
58 | }
59 | for (int i = 0, c = buffer.length(); i < c; i++) {
60 | context.writeCodeword(randomize255State(
61 | buffer.charAt(i), context.getCodewordCount() + 1));
62 | }
63 | }
64 |
65 | private static char randomize255State(char ch, int codewordPosition) {
66 | int pseudoRandom = ((149 * codewordPosition) % 255) + 1;
67 | int tempVariable = ch + pseudoRandom;
68 | if (tempVariable <= 255) {
69 | return (char) tempVariable;
70 | } else {
71 | return (char) (tempVariable - 256);
72 | }
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/datamatrix/encoder/DataMatrixSymbolInfo144.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2006 Jeremias Maerki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.datamatrix.encoder;
18 |
19 | final class DataMatrixSymbolInfo144 extends SymbolInfo {
20 |
21 | DataMatrixSymbolInfo144() {
22 | super(false, 1558, 620, 22, 22, 36, -1, 62);
23 | }
24 |
25 | @Override
26 | public int getInterleavedBlockCount() {
27 | return 10;
28 | }
29 |
30 | @Override
31 | public int getDataLengthForInterleavedBlock(int index) {
32 | return (index <= 8) ? 156 : 155;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/datamatrix/encoder/Encoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2006-2007 Jeremias Maerki.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.datamatrix.encoder;
18 |
19 | interface Encoder {
20 |
21 | int getEncodingMode();
22 |
23 | void encode(EncoderContext context);
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/datamatrix/encoder/SymbolShapeHint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 Jeremias Maerki.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.datamatrix.encoder;
18 |
19 | /**
20 | * Enumeration for DataMatrix symbol shape hint. It can be used to force square or rectangular
21 | * symbols.
22 | */
23 | public enum SymbolShapeHint {
24 |
25 | FORCE_NONE,
26 | FORCE_SQUARE,
27 | FORCE_RECTANGLE,
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/datamatrix/encoder/TextEncoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2006-2007 Jeremias Maerki.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.datamatrix.encoder;
18 |
19 | final class TextEncoder extends C40Encoder {
20 |
21 | @Override
22 | public int getEncodingMode() {
23 | return HighLevelEncoder.TEXT_ENCODATION;
24 | }
25 |
26 | @Override
27 | int encodeChar(char c, StringBuilder sb) {
28 | if (c == ' ') {
29 | sb.append('\3');
30 | return 1;
31 | }
32 | if (c >= '0' && c <= '9') {
33 | sb.append((char) (c - 48 + 4));
34 | return 1;
35 | }
36 | if (c >= 'a' && c <= 'z') {
37 | sb.append((char) (c - 97 + 14));
38 | return 1;
39 | }
40 | if (c < ' ') {
41 | sb.append('\0'); //Shift 1 Set
42 | sb.append(c);
43 | return 2;
44 | }
45 | if (c <= '/') {
46 | sb.append('\1'); //Shift 2 Set
47 | sb.append((char) (c - 33));
48 | return 2;
49 | }
50 | if (c <= '@') {
51 | sb.append('\1'); //Shift 2 Set
52 | sb.append((char) (c - 58 + 15));
53 | return 2;
54 | }
55 | if (c >= '[' && c <= '_') {
56 | sb.append('\1'); //Shift 2 Set
57 | sb.append((char) (c - 91 + 22));
58 | return 2;
59 | }
60 | if (c == '`') {
61 | sb.append('\2'); //Shift 3 Set
62 | sb.append((char) 0); // '`' - 96 == 0
63 | return 2;
64 | }
65 | if (c <= 'Z') {
66 | sb.append('\2'); //Shift 3 Set
67 | sb.append((char) (c - 65 + 1));
68 | return 2;
69 | }
70 | if (c <= 127) {
71 | sb.append('\2'); //Shift 3 Set
72 | sb.append((char) (c - 123 + 27));
73 | return 2;
74 | }
75 | sb.append("\1\u001e"); //Shift 2, Upper Shift
76 | int len = 2;
77 | len += encodeChar((char) (c - 128), sb);
78 | return len;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/multi/MultipleBarcodeReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.multi;
18 |
19 | import com.google.zxing.BinaryBitmap;
20 | import com.google.zxing.DecodeHintType;
21 | import com.google.zxing.NotFoundException;
22 | import com.google.zxing.Result;
23 |
24 | import java.util.Map;
25 |
26 | /**
27 | * Implementation of this interface attempt to read several barcodes from one image.
28 | *
29 | * @see com.google.zxing.Reader
30 | * @author Sean Owen
31 | */
32 | public interface MultipleBarcodeReader {
33 |
34 | Result[] decodeMultiple(BinaryBitmap image) throws NotFoundException;
35 |
36 | Result[] decodeMultiple(BinaryBitmap image,
37 | Map hints) throws NotFoundException;
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/multi/qrcode/detector/MultiDetector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.multi.qrcode.detector;
18 |
19 | import com.google.zxing.DecodeHintType;
20 | import com.google.zxing.NotFoundException;
21 | import com.google.zxing.ReaderException;
22 | import com.google.zxing.ResultPointCallback;
23 | import com.google.zxing.common.BitMatrix;
24 | import com.google.zxing.common.DetectorResult;
25 | import com.google.zxing.qrcode.detector.Detector;
26 | import com.google.zxing.qrcode.detector.FinderPatternInfo;
27 |
28 | import java.util.ArrayList;
29 | import java.util.List;
30 | import java.util.Map;
31 |
32 | /**
33 | *
Encapsulates logic that can detect one or more QR Codes in an image, even if the QR Code
34 | * is rotated or skewed, or partially obscured.
35 | *
36 | * @author Sean Owen
37 | * @author Hannes Erven
38 | */
39 | public final class MultiDetector extends Detector {
40 |
41 | private static final DetectorResult[] EMPTY_DETECTOR_RESULTS = new DetectorResult[0];
42 |
43 | public MultiDetector(BitMatrix image) {
44 | super(image);
45 | }
46 |
47 | public DetectorResult[] detectMulti(Map hints) throws NotFoundException {
48 | BitMatrix image = getImage();
49 | ResultPointCallback resultPointCallback =
50 | hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
51 | MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback);
52 | FinderPatternInfo[] infos = finder.findMulti(hints);
53 |
54 | if (infos.length == 0) {
55 | throw NotFoundException.getNotFoundInstance();
56 | }
57 |
58 | List result = new ArrayList<>();
59 | for (FinderPatternInfo info : infos) {
60 | try {
61 | result.add(processFinderPatternInfo(info));
62 | } catch (ReaderException e) {
63 | // ignore
64 | }
65 | }
66 | if (result.isEmpty()) {
67 | return EMPTY_DETECTOR_RESULTS;
68 | } else {
69 | return result.toArray(EMPTY_DETECTOR_RESULTS);
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/EAN8Reader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.oned;
18 |
19 | import com.google.zxing.BarcodeFormat;
20 | import com.google.zxing.NotFoundException;
21 | import com.google.zxing.common.BitArray;
22 |
23 | /**
24 | *
Implements decoding of the EAN-8 format.
25 | *
26 | * @author Sean Owen
27 | */
28 | public final class EAN8Reader extends UPCEANReader {
29 |
30 | private final int[] decodeMiddleCounters;
31 |
32 | public EAN8Reader() {
33 | decodeMiddleCounters = new int[4];
34 | }
35 |
36 | @Override
37 | protected int decodeMiddle(BitArray row,
38 | int[] startRange,
39 | StringBuilder result) throws NotFoundException {
40 | int[] counters = decodeMiddleCounters;
41 | counters[0] = 0;
42 | counters[1] = 0;
43 | counters[2] = 0;
44 | counters[3] = 0;
45 | int end = row.getSize();
46 | int rowOffset = startRange[1];
47 |
48 | for (int x = 0; x < 4 && rowOffset < end; x++) {
49 | int bestMatch = decodeDigit(row, counters, rowOffset, L_PATTERNS);
50 | result.append((char) ('0' + bestMatch));
51 | for (int counter : counters) {
52 | rowOffset += counter;
53 | }
54 | }
55 |
56 | int[] middleRange = findGuardPattern(row, rowOffset, true, MIDDLE_PATTERN);
57 | rowOffset = middleRange[1];
58 |
59 | for (int x = 0; x < 4 && rowOffset < end; x++) {
60 | int bestMatch = decodeDigit(row, counters, rowOffset, L_PATTERNS);
61 | result.append((char) ('0' + bestMatch));
62 | for (int counter : counters) {
63 | rowOffset += counter;
64 | }
65 | }
66 |
67 | return rowOffset;
68 | }
69 |
70 | @Override
71 | BarcodeFormat getBarcodeFormat() {
72 | return BarcodeFormat.EAN_8;
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/UPCAWriter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.oned;
18 |
19 | import com.google.zxing.BarcodeFormat;
20 | import com.google.zxing.EncodeHintType;
21 | import com.google.zxing.Writer;
22 | import com.google.zxing.common.BitMatrix;
23 |
24 | import java.util.Map;
25 |
26 | /**
27 | * This object renders a UPC-A code as a {@link BitMatrix}.
28 | *
29 | * @author qwandor@google.com (Andrew Walbran)
30 | */
31 | public final class UPCAWriter implements Writer {
32 |
33 | private final EAN13Writer subWriter = new EAN13Writer();
34 |
35 | @Override
36 | public BitMatrix encode(String contents, BarcodeFormat format, int width, int height) {
37 | return encode(contents, format, width, height, null);
38 | }
39 |
40 | @Override
41 | public BitMatrix encode(String contents,
42 | BarcodeFormat format,
43 | int width,
44 | int height,
45 | Map hints) {
46 | if (format != BarcodeFormat.UPC_A) {
47 | throw new IllegalArgumentException("Can only encode UPC-A, but got " + format);
48 | }
49 | // Transform a UPC-A code into the equivalent EAN-13 code and write it that way
50 | return subWriter.encode('0' + contents, BarcodeFormat.EAN_13, width, height, hints);
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/UPCEANExtensionSupport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.oned;
18 |
19 | import com.google.zxing.NotFoundException;
20 | import com.google.zxing.ReaderException;
21 | import com.google.zxing.Result;
22 | import com.google.zxing.common.BitArray;
23 |
24 | final class UPCEANExtensionSupport {
25 |
26 | private static final int[] EXTENSION_START_PATTERN = {1,1,2};
27 |
28 | private final UPCEANExtension2Support twoSupport = new UPCEANExtension2Support();
29 | private final UPCEANExtension5Support fiveSupport = new UPCEANExtension5Support();
30 |
31 | Result decodeRow(int rowNumber, BitArray row, int rowOffset) throws NotFoundException {
32 | int[] extensionStartRange = UPCEANReader.findGuardPattern(row, rowOffset, false, EXTENSION_START_PATTERN);
33 | try {
34 | return fiveSupport.decodeRow(rowNumber, row, extensionStartRange);
35 | } catch (ReaderException ignored) {
36 | return twoSupport.decodeRow(rowNumber, row, extensionStartRange);
37 | }
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/UPCEANWriter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.oned;
18 |
19 | /**
20 | *
Encapsulates functionality and implementation that is common to UPC and EAN families
21 | * of one-dimensional barcodes.
22 | *
23 | * @author aripollak@gmail.com (Ari Pollak)
24 | * @author dsbnatut@gmail.com (Kazuki Nishiura)
25 | */
26 | public abstract class UPCEANWriter extends OneDimensionalCodeWriter {
27 |
28 | @Override
29 | public int getDefaultMargin() {
30 | // Use a different default more appropriate for UPC/EAN
31 | return 9;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/DataCharacter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.oned.rss;
18 |
19 | /**
20 | * Encapsulates a since character value in an RSS barcode, including its checksum information.
21 | */
22 | public class DataCharacter {
23 |
24 | private final int value;
25 | private final int checksumPortion;
26 |
27 | public DataCharacter(int value, int checksumPortion) {
28 | this.value = value;
29 | this.checksumPortion = checksumPortion;
30 | }
31 |
32 | public final int getValue() {
33 | return value;
34 | }
35 |
36 | public final int getChecksumPortion() {
37 | return checksumPortion;
38 | }
39 |
40 | @Override
41 | public final String toString() {
42 | return value + "(" + checksumPortion + ')';
43 | }
44 |
45 | @Override
46 | public final boolean equals(Object o) {
47 | if (!(o instanceof DataCharacter)) {
48 | return false;
49 | }
50 | DataCharacter that = (DataCharacter) o;
51 | return value == that.value && checksumPortion == that.checksumPortion;
52 | }
53 |
54 | @Override
55 | public final int hashCode() {
56 | return value ^ checksumPortion;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/FinderPattern.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.oned.rss;
18 |
19 | import com.google.zxing.ResultPoint;
20 |
21 | /**
22 | * Encapsulates an RSS barcode finder pattern, including its start/end position and row.
23 | */
24 | public final class FinderPattern {
25 |
26 | private final int value;
27 | private final int[] startEnd;
28 | private final ResultPoint[] resultPoints;
29 |
30 | public FinderPattern(int value, int[] startEnd, int start, int end, int rowNumber) {
31 | this.value = value;
32 | this.startEnd = startEnd;
33 | this.resultPoints = new ResultPoint[] {
34 | new ResultPoint(start, rowNumber),
35 | new ResultPoint(end, rowNumber),
36 | };
37 | }
38 |
39 | public int getValue() {
40 | return value;
41 | }
42 |
43 | public int[] getStartEnd() {
44 | return startEnd;
45 | }
46 |
47 | public ResultPoint[] getResultPoints() {
48 | return resultPoints;
49 | }
50 |
51 | @Override
52 | public boolean equals(Object o) {
53 | if (!(o instanceof FinderPattern)) {
54 | return false;
55 | }
56 | FinderPattern that = (FinderPattern) o;
57 | return value == that.value;
58 | }
59 |
60 | @Override
61 | public int hashCode() {
62 | return value;
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/Pair.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.oned.rss;
18 |
19 | final class Pair extends DataCharacter {
20 |
21 | private final FinderPattern finderPattern;
22 | private int count;
23 |
24 | Pair(int value, int checksumPortion, FinderPattern finderPattern) {
25 | super(value, checksumPortion);
26 | this.finderPattern = finderPattern;
27 | }
28 |
29 | FinderPattern getFinderPattern() {
30 | return finderPattern;
31 | }
32 |
33 | int getCount() {
34 | return count;
35 | }
36 |
37 | void incrementCount() {
38 | count++;
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/RSSUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.oned.rss;
18 |
19 | /** Adapted from listings in ISO/IEC 24724 Appendix B and Appendix G. */
20 | public final class RSSUtils {
21 |
22 | private RSSUtils() {}
23 |
24 | public static int getRSSvalue(int[] widths, int maxWidth, boolean noNarrow) {
25 | int n = 0;
26 | for (int width : widths) {
27 | n += width;
28 | }
29 | int val = 0;
30 | int narrowMask = 0;
31 | int elements = widths.length;
32 | for (int bar = 0; bar < elements - 1; bar++) {
33 | int elmWidth;
34 | for (elmWidth = 1, narrowMask |= 1 << bar;
35 | elmWidth < widths[bar];
36 | elmWidth++, narrowMask &= ~(1 << bar)) {
37 | int subVal = combins(n - elmWidth - 1, elements - bar - 2);
38 | if (noNarrow && (narrowMask == 0) &&
39 | (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) {
40 | subVal -= combins(n - elmWidth - (elements - bar),
41 | elements - bar - 2);
42 | }
43 | if (elements - bar - 1 > 1) {
44 | int lessVal = 0;
45 | for (int mxwElement = n - elmWidth - (elements - bar - 2);
46 | mxwElement > maxWidth; mxwElement--) {
47 | lessVal += combins(n - elmWidth - mxwElement - 1,
48 | elements - bar - 3);
49 | }
50 | subVal -= lessVal * (elements - 1 - bar);
51 | } else if (n - elmWidth > maxWidth) {
52 | subVal--;
53 | }
54 | val += subVal;
55 | }
56 | n -= elmWidth;
57 | }
58 | return val;
59 | }
60 |
61 | private static int combins(int n, int r) {
62 | int maxDenom;
63 | int minDenom;
64 | if (n - r > r) {
65 | minDenom = r;
66 | maxDenom = n - r;
67 | } else {
68 | minDenom = n - r;
69 | maxDenom = r;
70 | }
71 | int val = 1;
72 | int j = 1;
73 | for (int i = n; i > maxDenom; i--) {
74 | val *= i;
75 | if (j <= minDenom) {
76 | val /= j;
77 | j++;
78 | }
79 | }
80 | while (j <= minDenom) {
81 | val /= j;
82 | j++;
83 | }
84 | return val;
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/BitArrayBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded;
28 |
29 | import com.google.zxing.common.BitArray;
30 |
31 | import java.util.List;
32 |
33 | /**
34 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
35 | * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
36 | */
37 | final class BitArrayBuilder {
38 |
39 | private BitArrayBuilder() {
40 | }
41 |
42 | static BitArray buildBitArray(List pairs) {
43 | int charNumber = (pairs.size() * 2) - 1;
44 | if (pairs.get(pairs.size() - 1).getRightChar() == null) {
45 | charNumber -= 1;
46 | }
47 |
48 | int size = 12 * charNumber;
49 |
50 | BitArray binary = new BitArray(size);
51 | int accPos = 0;
52 |
53 | ExpandedPair firstPair = pairs.get(0);
54 | int firstValue = firstPair.getRightChar().getValue();
55 | for (int i = 11; i >= 0; --i) {
56 | if ((firstValue & (1 << i)) != 0) {
57 | binary.set(accPos);
58 | }
59 | accPos++;
60 | }
61 |
62 | for (int i = 1; i < pairs.size(); ++i) {
63 | ExpandedPair currentPair = pairs.get(i);
64 |
65 | int leftValue = currentPair.getLeftChar().getValue();
66 | for (int j = 11; j >= 0; --j) {
67 | if ((leftValue & (1 << j)) != 0) {
68 | binary.set(accPos);
69 | }
70 | accPos++;
71 | }
72 |
73 | if (currentPair.getRightChar() != null) {
74 | int rightValue = currentPair.getRightChar().getValue();
75 | for (int j = 11; j >= 0; --j) {
76 | if ((rightValue & (1 << j)) != 0) {
77 | binary.set(accPos);
78 | }
79 | accPos++;
80 | }
81 | }
82 | }
83 | return binary;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/ExpandedPair.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded;
28 |
29 | import com.google.zxing.oned.rss.DataCharacter;
30 | import com.google.zxing.oned.rss.FinderPattern;
31 |
32 | import java.util.Objects;
33 |
34 | /**
35 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
36 | */
37 | final class ExpandedPair {
38 |
39 | private final DataCharacter leftChar;
40 | private final DataCharacter rightChar;
41 | private final FinderPattern finderPattern;
42 |
43 | ExpandedPair(DataCharacter leftChar,
44 | DataCharacter rightChar,
45 | FinderPattern finderPattern) {
46 | this.leftChar = leftChar;
47 | this.rightChar = rightChar;
48 | this.finderPattern = finderPattern;
49 | }
50 |
51 | DataCharacter getLeftChar() {
52 | return this.leftChar;
53 | }
54 |
55 | DataCharacter getRightChar() {
56 | return this.rightChar;
57 | }
58 |
59 | FinderPattern getFinderPattern() {
60 | return this.finderPattern;
61 | }
62 |
63 | boolean mustBeLast() {
64 | return this.rightChar == null;
65 | }
66 |
67 | @Override
68 | public String toString() {
69 | return
70 | "[ " + leftChar + " , " + rightChar + " : " +
71 | (finderPattern == null ? "null" : finderPattern.getValue()) + " ]";
72 | }
73 |
74 | @Override
75 | public boolean equals(Object o) {
76 | if (!(o instanceof ExpandedPair)) {
77 | return false;
78 | }
79 | ExpandedPair that = (ExpandedPair) o;
80 | return Objects.equals(leftChar, that.leftChar) &&
81 | Objects.equals(rightChar, that.rightChar) &&
82 | Objects.equals(finderPattern, that.finderPattern);
83 | }
84 |
85 | @Override
86 | public int hashCode() {
87 | return Objects.hashCode(leftChar) ^ Objects.hashCode(rightChar) ^ Objects.hashCode(finderPattern);
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/ExpandedRow.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.oned.rss.expanded;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | /**
23 | * One row of an RSS Expanded Stacked symbol, consisting of 1+ expanded pairs.
24 | */
25 | final class ExpandedRow {
26 |
27 | private final List pairs;
28 | private final int rowNumber;
29 | /** Did this row of the image have to be reversed (mirrored) to recognize the pairs? */
30 | private final boolean wasReversed;
31 |
32 | ExpandedRow(List pairs, int rowNumber, boolean wasReversed) {
33 | this.pairs = new ArrayList<>(pairs);
34 | this.rowNumber = rowNumber;
35 | this.wasReversed = wasReversed;
36 | }
37 |
38 | List getPairs() {
39 | return this.pairs;
40 | }
41 |
42 | int getRowNumber() {
43 | return this.rowNumber;
44 | }
45 |
46 | boolean isEquivalent(List otherPairs) {
47 | return this.pairs.equals(otherPairs);
48 | }
49 |
50 | @Override
51 | public String toString() {
52 | return "{ " + pairs + " }";
53 | }
54 |
55 | /**
56 | * Two rows are equal if they contain the same pairs in the same order.
57 | */
58 | @Override
59 | public boolean equals(Object o) {
60 | if (!(o instanceof ExpandedRow)) {
61 | return false;
62 | }
63 | ExpandedRow that = (ExpandedRow) o;
64 | return this.pairs.equals(that.pairs) && wasReversed == that.wasReversed;
65 | }
66 |
67 | @Override
68 | public int hashCode() {
69 | return pairs.hashCode() ^ Boolean.valueOf(wasReversed).hashCode();
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI013103decoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | import com.google.zxing.common.BitArray;
30 |
31 | /**
32 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
33 | */
34 | final class AI013103decoder extends AI013x0xDecoder {
35 |
36 | AI013103decoder(BitArray information) {
37 | super(information);
38 | }
39 |
40 | @Override
41 | protected void addWeightCode(StringBuilder buf, int weight) {
42 | buf.append("(3103)");
43 | }
44 |
45 | @Override
46 | protected int checkWeight(int weight) {
47 | return weight;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01320xDecoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | import com.google.zxing.common.BitArray;
30 |
31 | /**
32 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
33 | */
34 | final class AI01320xDecoder extends AI013x0xDecoder {
35 |
36 | AI01320xDecoder(BitArray information) {
37 | super(information);
38 | }
39 |
40 | @Override
41 | protected void addWeightCode(StringBuilder buf, int weight) {
42 | if (weight < 10000) {
43 | buf.append("(3202)");
44 | } else {
45 | buf.append("(3203)");
46 | }
47 | }
48 |
49 | @Override
50 | protected int checkWeight(int weight) {
51 | if (weight < 10000) {
52 | return weight;
53 | }
54 | return weight - 10000;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01392xDecoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | import com.google.zxing.FormatException;
30 | import com.google.zxing.NotFoundException;
31 | import com.google.zxing.common.BitArray;
32 |
33 | /**
34 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
35 | */
36 | final class AI01392xDecoder extends AI01decoder {
37 |
38 | private static final int HEADER_SIZE = 5 + 1 + 2;
39 | private static final int LAST_DIGIT_SIZE = 2;
40 |
41 | AI01392xDecoder(BitArray information) {
42 | super(information);
43 | }
44 |
45 | @Override
46 | public String parseInformation() throws NotFoundException, FormatException {
47 | if (this.getInformation().getSize() < HEADER_SIZE + GTIN_SIZE) {
48 | throw NotFoundException.getNotFoundInstance();
49 | }
50 |
51 | StringBuilder buf = new StringBuilder();
52 |
53 | encodeCompressedGtin(buf, HEADER_SIZE);
54 |
55 | int lastAIdigit =
56 | this.getGeneralDecoder().extractNumericValueFromBitArray(HEADER_SIZE + GTIN_SIZE, LAST_DIGIT_SIZE);
57 | buf.append("(392");
58 | buf.append(lastAIdigit);
59 | buf.append(')');
60 |
61 | DecodedInformation decodedInformation =
62 | this.getGeneralDecoder().decodeGeneralPurposeField(HEADER_SIZE + GTIN_SIZE + LAST_DIGIT_SIZE, null);
63 | buf.append(decodedInformation.getNewString());
64 |
65 | return buf.toString();
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI013x0xDecoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | import com.google.zxing.NotFoundException;
30 | import com.google.zxing.common.BitArray;
31 |
32 | /**
33 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
34 | */
35 | abstract class AI013x0xDecoder extends AI01weightDecoder {
36 |
37 | private static final int HEADER_SIZE = 4 + 1;
38 | private static final int WEIGHT_SIZE = 15;
39 |
40 | AI013x0xDecoder(BitArray information) {
41 | super(information);
42 | }
43 |
44 | @Override
45 | public String parseInformation() throws NotFoundException {
46 | if (this.getInformation().getSize() != HEADER_SIZE + GTIN_SIZE + WEIGHT_SIZE) {
47 | throw NotFoundException.getNotFoundInstance();
48 | }
49 |
50 | StringBuilder buf = new StringBuilder();
51 |
52 | encodeCompressedGtin(buf, HEADER_SIZE);
53 | encodeCompressedWeight(buf, HEADER_SIZE + GTIN_SIZE, WEIGHT_SIZE);
54 |
55 | return buf.toString();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01AndOtherAIs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | import com.google.zxing.FormatException;
30 | import com.google.zxing.NotFoundException;
31 | import com.google.zxing.common.BitArray;
32 |
33 | /**
34 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
35 | * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
36 | */
37 | final class AI01AndOtherAIs extends AI01decoder {
38 |
39 | private static final int HEADER_SIZE = 1 + 1 + 2; //first bit encodes the linkage flag,
40 | //the second one is the encodation method, and the other two are for the variable length
41 | AI01AndOtherAIs(BitArray information) {
42 | super(information);
43 | }
44 |
45 | @Override
46 | public String parseInformation() throws NotFoundException, FormatException {
47 | StringBuilder buff = new StringBuilder();
48 |
49 | buff.append("(01)");
50 | int initialGtinPosition = buff.length();
51 | int firstGtinDigit = this.getGeneralDecoder().extractNumericValueFromBitArray(HEADER_SIZE, 4);
52 | buff.append(firstGtinDigit);
53 |
54 | this.encodeCompressedGtinWithoutAI(buff, HEADER_SIZE + 4, initialGtinPosition);
55 |
56 | return this.getGeneralDecoder().decodeAllCodes(buff, HEADER_SIZE + 44);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01decoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | import com.google.zxing.common.BitArray;
30 |
31 | /**
32 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
33 | * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
34 | */
35 | abstract class AI01decoder extends AbstractExpandedDecoder {
36 |
37 | static final int GTIN_SIZE = 40;
38 |
39 | AI01decoder(BitArray information) {
40 | super(information);
41 | }
42 |
43 | final void encodeCompressedGtin(StringBuilder buf, int currentPos) {
44 | buf.append("(01)");
45 | int initialPosition = buf.length();
46 | buf.append('9');
47 |
48 | encodeCompressedGtinWithoutAI(buf, currentPos, initialPosition);
49 | }
50 |
51 | final void encodeCompressedGtinWithoutAI(StringBuilder buf, int currentPos, int initialBufferPosition) {
52 | for (int i = 0; i < 4; ++i) {
53 | int currentBlock = this.getGeneralDecoder().extractNumericValueFromBitArray(currentPos + 10 * i, 10);
54 | if (currentBlock / 100 == 0) {
55 | buf.append('0');
56 | }
57 | if (currentBlock / 10 == 0) {
58 | buf.append('0');
59 | }
60 | buf.append(currentBlock);
61 | }
62 |
63 | appendCheckDigit(buf, initialBufferPosition);
64 | }
65 |
66 | private static void appendCheckDigit(StringBuilder buf, int currentPos) {
67 | int checkDigit = 0;
68 | for (int i = 0; i < 13; i++) {
69 | int digit = buf.charAt(i + currentPos) - '0';
70 | checkDigit += (i & 0x01) == 0 ? 3 * digit : digit;
71 | }
72 |
73 | checkDigit = 10 - (checkDigit % 10);
74 | if (checkDigit == 10) {
75 | checkDigit = 0;
76 | }
77 |
78 | buf.append(checkDigit);
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01weightDecoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | import com.google.zxing.common.BitArray;
30 |
31 | /**
32 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
33 | */
34 | abstract class AI01weightDecoder extends AI01decoder {
35 |
36 | AI01weightDecoder(BitArray information) {
37 | super(information);
38 | }
39 |
40 | final void encodeCompressedWeight(StringBuilder buf, int currentPos, int weightSize) {
41 | int originalWeightNumeric = this.getGeneralDecoder().extractNumericValueFromBitArray(currentPos, weightSize);
42 | addWeightCode(buf, originalWeightNumeric);
43 |
44 | int weightNumeric = checkWeight(originalWeightNumeric);
45 |
46 | int currentDivisor = 100000;
47 | for (int i = 0; i < 5; ++i) {
48 | if (weightNumeric / currentDivisor == 0) {
49 | buf.append('0');
50 | }
51 | currentDivisor /= 10;
52 | }
53 | buf.append(weightNumeric);
54 | }
55 |
56 | protected abstract void addWeightCode(StringBuilder buf, int weight);
57 |
58 | protected abstract int checkWeight(int weight);
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AnyAIDecoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | import com.google.zxing.FormatException;
30 | import com.google.zxing.NotFoundException;
31 | import com.google.zxing.common.BitArray;
32 |
33 | /**
34 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
35 | * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
36 | */
37 | final class AnyAIDecoder extends AbstractExpandedDecoder {
38 |
39 | private static final int HEADER_SIZE = 2 + 1 + 2;
40 |
41 | AnyAIDecoder(BitArray information) {
42 | super(information);
43 | }
44 |
45 | @Override
46 | public String parseInformation() throws NotFoundException, FormatException {
47 | StringBuilder buf = new StringBuilder();
48 | return this.getGeneralDecoder().decodeAllCodes(buf, HEADER_SIZE);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/BlockParsedResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | /**
30 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
31 | * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
32 | */
33 | final class BlockParsedResult {
34 |
35 | private final DecodedInformation decodedInformation;
36 | private final boolean finished;
37 |
38 | BlockParsedResult() {
39 | this(null, false);
40 | }
41 |
42 | BlockParsedResult(DecodedInformation information, boolean finished) {
43 | this.finished = finished;
44 | this.decodedInformation = information;
45 | }
46 |
47 | DecodedInformation getDecodedInformation() {
48 | return this.decodedInformation;
49 | }
50 |
51 | boolean isFinished() {
52 | return this.finished;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/CurrentParsingState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | /**
30 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
31 | */
32 | final class CurrentParsingState {
33 |
34 | private int position;
35 | private State encoding;
36 |
37 | private enum State {
38 | NUMERIC,
39 | ALPHA,
40 | ISO_IEC_646
41 | }
42 |
43 | CurrentParsingState() {
44 | this.position = 0;
45 | this.encoding = State.NUMERIC;
46 | }
47 |
48 | int getPosition() {
49 | return position;
50 | }
51 |
52 | void setPosition(int position) {
53 | this.position = position;
54 | }
55 |
56 | void incrementPosition(int delta) {
57 | position += delta;
58 | }
59 |
60 | boolean isAlpha() {
61 | return this.encoding == State.ALPHA;
62 | }
63 |
64 | boolean isNumeric() {
65 | return this.encoding == State.NUMERIC;
66 | }
67 |
68 | boolean isIsoIec646() {
69 | return this.encoding == State.ISO_IEC_646;
70 | }
71 |
72 | void setNumeric() {
73 | this.encoding = State.NUMERIC;
74 | }
75 |
76 | void setAlpha() {
77 | this.encoding = State.ALPHA;
78 | }
79 |
80 | void setIsoIec646() {
81 | this.encoding = State.ISO_IEC_646;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/DecodedChar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | /**
30 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
31 | * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
32 | */
33 | final class DecodedChar extends DecodedObject {
34 |
35 | private final char value;
36 |
37 | static final char FNC1 = '$'; // It's not in Alphanumeric neither in ISO/IEC 646 charset
38 |
39 | DecodedChar(int newPosition, char value) {
40 | super(newPosition);
41 | this.value = value;
42 | }
43 |
44 | char getValue() {
45 | return this.value;
46 | }
47 |
48 | boolean isFNC1() {
49 | return this.value == FNC1;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/DecodedInformation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | /**
30 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
31 | * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
32 | */
33 | final class DecodedInformation extends DecodedObject {
34 |
35 | private final String newString;
36 | private final int remainingValue;
37 | private final boolean remaining;
38 |
39 | DecodedInformation(int newPosition, String newString) {
40 | super(newPosition);
41 | this.newString = newString;
42 | this.remaining = false;
43 | this.remainingValue = 0;
44 | }
45 |
46 | DecodedInformation(int newPosition, String newString, int remainingValue) {
47 | super(newPosition);
48 | this.remaining = true;
49 | this.remainingValue = remainingValue;
50 | this.newString = newString;
51 | }
52 |
53 | String getNewString() {
54 | return this.newString;
55 | }
56 |
57 | boolean isRemaining() {
58 | return this.remaining;
59 | }
60 |
61 | int getRemainingValue() {
62 | return this.remainingValue;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/DecodedNumeric.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | import com.google.zxing.FormatException;
30 |
31 | /**
32 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
33 | * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
34 | */
35 | final class DecodedNumeric extends DecodedObject {
36 |
37 | private final int firstDigit;
38 | private final int secondDigit;
39 |
40 | static final int FNC1 = 10;
41 |
42 | DecodedNumeric(int newPosition, int firstDigit, int secondDigit) throws FormatException {
43 | super(newPosition);
44 |
45 | if (firstDigit < 0 || firstDigit > 10 || secondDigit < 0 || secondDigit > 10) {
46 | throw FormatException.getFormatInstance();
47 | }
48 |
49 | this.firstDigit = firstDigit;
50 | this.secondDigit = secondDigit;
51 | }
52 |
53 | int getFirstDigit() {
54 | return this.firstDigit;
55 | }
56 |
57 | int getSecondDigit() {
58 | return this.secondDigit;
59 | }
60 |
61 | int getValue() {
62 | return this.firstDigit * 10 + this.secondDigit;
63 | }
64 |
65 | boolean isFirstDigitFNC1() {
66 | return this.firstDigit == FNC1;
67 | }
68 |
69 | boolean isSecondDigitFNC1() {
70 | return this.secondDigit == FNC1;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/oned/rss/expanded/decoders/DecodedObject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * These authors would like to acknowledge the Spanish Ministry of Industry,
19 | * Tourism and Trade, for the support in the project TSI020301-2008-2
20 | * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 | * Mobile Dynamic Environments", led by Treelogic
22 | * ( http://www.treelogic.com/ ):
23 | *
24 | * http://www.piramidepse.com/
25 | */
26 |
27 | package com.google.zxing.oned.rss.expanded.decoders;
28 |
29 | /**
30 | * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
31 | */
32 | abstract class DecodedObject {
33 |
34 | private final int newPosition;
35 |
36 | DecodedObject(int newPosition) {
37 | this.newPosition = newPosition;
38 | }
39 |
40 | final int getNewPosition() {
41 | return this.newPosition;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/pdf417/decoder/BarcodeMetadata.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.pdf417.decoder;
18 |
19 | /**
20 | * @author Guenther Grau
21 | */
22 | final class BarcodeMetadata {
23 |
24 | private final int columnCount;
25 | private final int errorCorrectionLevel;
26 | private final int rowCountUpperPart;
27 | private final int rowCountLowerPart;
28 | private final int rowCount;
29 |
30 | BarcodeMetadata(int columnCount, int rowCountUpperPart, int rowCountLowerPart, int errorCorrectionLevel) {
31 | this.columnCount = columnCount;
32 | this.errorCorrectionLevel = errorCorrectionLevel;
33 | this.rowCountUpperPart = rowCountUpperPart;
34 | this.rowCountLowerPart = rowCountLowerPart;
35 | this.rowCount = rowCountUpperPart + rowCountLowerPart;
36 | }
37 |
38 | int getColumnCount() {
39 | return columnCount;
40 | }
41 |
42 | int getErrorCorrectionLevel() {
43 | return errorCorrectionLevel;
44 | }
45 |
46 | int getRowCount() {
47 | return rowCount;
48 | }
49 |
50 | int getRowCountUpperPart() {
51 | return rowCountUpperPart;
52 | }
53 |
54 | int getRowCountLowerPart() {
55 | return rowCountLowerPart;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/pdf417/decoder/BarcodeValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.pdf417.decoder;
18 |
19 | import com.google.zxing.pdf417.PDF417Common;
20 |
21 | import java.util.ArrayList;
22 | import java.util.Collection;
23 | import java.util.HashMap;
24 | import java.util.Map;
25 | import java.util.Map.Entry;
26 |
27 | /**
28 | * @author Guenther Grau
29 | */
30 | final class BarcodeValue {
31 | private final Map values = new HashMap<>();
32 |
33 | /**
34 | * Add an occurrence of a value
35 | */
36 | void setValue(int value) {
37 | Integer confidence = values.get(value);
38 | if (confidence == null) {
39 | confidence = 0;
40 | }
41 | confidence++;
42 | values.put(value, confidence);
43 | }
44 |
45 | /**
46 | * Determines the maximum occurrence of a set value and returns all values which were set with this occurrence.
47 | * @return an array of int, containing the values with the highest occurrence, or null, if no value was set
48 | */
49 | int[] getValue() {
50 | int maxConfidence = -1;
51 | Collection result = new ArrayList<>();
52 | for (Entry entry : values.entrySet()) {
53 | if (entry.getValue() > maxConfidence) {
54 | maxConfidence = entry.getValue();
55 | result.clear();
56 | result.add(entry.getKey());
57 | } else if (entry.getValue() == maxConfidence) {
58 | result.add(entry.getKey());
59 | }
60 | }
61 | return PDF417Common.toIntArray(result);
62 | }
63 |
64 | Integer getConfidence(int value) {
65 | return values.get(value);
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/pdf417/decoder/Codeword.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.pdf417.decoder;
18 |
19 | /**
20 | * @author Guenther Grau
21 | */
22 | final class Codeword {
23 |
24 | private static final int BARCODE_ROW_UNKNOWN = -1;
25 |
26 | private final int startX;
27 | private final int endX;
28 | private final int bucket;
29 | private final int value;
30 | private int rowNumber = BARCODE_ROW_UNKNOWN;
31 |
32 | Codeword(int startX, int endX, int bucket, int value) {
33 | this.startX = startX;
34 | this.endX = endX;
35 | this.bucket = bucket;
36 | this.value = value;
37 | }
38 |
39 | boolean hasValidRowNumber() {
40 | return isValidRowNumber(rowNumber);
41 | }
42 |
43 | boolean isValidRowNumber(int rowNumber) {
44 | return rowNumber != BARCODE_ROW_UNKNOWN && bucket == (rowNumber % 3) * 3;
45 | }
46 |
47 | void setRowNumberAsRowIndicatorColumn() {
48 | rowNumber = (value / 30) * 3 + bucket / 3;
49 | }
50 |
51 | int getWidth() {
52 | return endX - startX;
53 | }
54 |
55 | int getStartX() {
56 | return startX;
57 | }
58 |
59 | int getEndX() {
60 | return endX;
61 | }
62 |
63 | int getBucket() {
64 | return bucket;
65 | }
66 |
67 | int getValue() {
68 | return value;
69 | }
70 |
71 | int getRowNumber() {
72 | return rowNumber;
73 | }
74 |
75 | void setRowNumber(int rowNumber) {
76 | this.rowNumber = rowNumber;
77 | }
78 |
79 | @Override
80 | public String toString() {
81 | return rowNumber + "|" + value;
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/pdf417/detector/PDF417DetectorResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.pdf417.detector;
18 |
19 | import com.google.zxing.ResultPoint;
20 | import com.google.zxing.common.BitMatrix;
21 |
22 | import java.util.List;
23 |
24 | /**
25 | * @author Guenther Grau
26 | */
27 | public final class PDF417DetectorResult {
28 |
29 | private final BitMatrix bits;
30 | private final List points;
31 |
32 | public PDF417DetectorResult(BitMatrix bits, List points) {
33 | this.bits = bits;
34 | this.points = points;
35 | }
36 |
37 | public BitMatrix getBits() {
38 | return bits;
39 | }
40 |
41 | public List getPoints() {
42 | return points;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/pdf417/encoder/BarcodeMatrix.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.pdf417.encoder;
18 |
19 | /**
20 | * Holds all of the information for a barcode in a format where it can be easily accessible
21 | *
22 | * @author Jacob Haynes
23 | */
24 | public final class BarcodeMatrix {
25 |
26 | private final BarcodeRow[] matrix;
27 | private int currentRow;
28 | private final int height;
29 | private final int width;
30 |
31 | /**
32 | * @param height the height of the matrix (Rows)
33 | * @param width the width of the matrix (Cols)
34 | */
35 | BarcodeMatrix(int height, int width) {
36 | matrix = new BarcodeRow[height];
37 | //Initializes the array to the correct width
38 | for (int i = 0, matrixLength = matrix.length; i < matrixLength; i++) {
39 | matrix[i] = new BarcodeRow((width + 4) * 17 + 1);
40 | }
41 | this.width = width * 17;
42 | this.height = height;
43 | this.currentRow = -1;
44 | }
45 |
46 | void set(int x, int y, byte value) {
47 | matrix[y].set(x, value);
48 | }
49 |
50 | void startRow() {
51 | ++currentRow;
52 | }
53 |
54 | BarcodeRow getCurrentRow() {
55 | return matrix[currentRow];
56 | }
57 |
58 | public byte[][] getMatrix() {
59 | return getScaledMatrix(1, 1);
60 | }
61 |
62 | public byte[][] getScaledMatrix(int xScale, int yScale) {
63 | byte[][] matrixOut = new byte[height * yScale][width * xScale];
64 | int yMax = height * yScale;
65 | for (int i = 0; i < yMax; i++) {
66 | matrixOut[yMax - i - 1] = matrix[i / yScale].getScaledRow(xScale);
67 | }
68 | return matrixOut;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/pdf417/encoder/BarcodeRow.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.pdf417.encoder;
18 |
19 | /**
20 | * @author Jacob Haynes
21 | */
22 | final class BarcodeRow {
23 |
24 | private final byte[] row;
25 | //A tacker for position in the bar
26 | private int currentLocation;
27 |
28 | /**
29 | * Creates a Barcode row of the width
30 | */
31 | BarcodeRow(int width) {
32 | this.row = new byte[width];
33 | currentLocation = 0;
34 | }
35 |
36 | /**
37 | * Sets a specific location in the bar
38 | *
39 | * @param x The location in the bar
40 | * @param value Black if true, white if false;
41 | */
42 | void set(int x, byte value) {
43 | row[x] = value;
44 | }
45 |
46 | /**
47 | * Sets a specific location in the bar
48 | *
49 | * @param x The location in the bar
50 | * @param black Black if true, white if false;
51 | */
52 | private void set(int x, boolean black) {
53 | row[x] = (byte) (black ? 1 : 0);
54 | }
55 |
56 | /**
57 | * @param black A boolean which is true if the bar black false if it is white
58 | * @param width How many spots wide the bar is.
59 | */
60 | void addBar(boolean black, int width) {
61 | for (int ii = 0; ii < width; ii++) {
62 | set(currentLocation++, black);
63 | }
64 | }
65 |
66 | /**
67 | * This function scales the row
68 | *
69 | * @param scale How much you want the image to be scaled, must be greater than or equal to 1.
70 | * @return the scaled row
71 | */
72 | byte[] getScaledRow(int scale) {
73 | byte[] output = new byte[row.length * scale];
74 | for (int i = 0; i < output.length; i++) {
75 | output[i] = row[i / scale];
76 | }
77 | return output;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/pdf417/encoder/Compaction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.pdf417.encoder;
18 |
19 | /**
20 | * Represents possible PDF417 barcode compaction types.
21 | */
22 | public enum Compaction {
23 |
24 | AUTO,
25 | TEXT,
26 | BYTE,
27 | NUMERIC
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/pdf417/encoder/Dimensions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.pdf417.encoder;
18 |
19 | /**
20 | * Data object to specify the minimum and maximum number of rows and columns for a PDF417 barcode.
21 | *
22 | * @author qwandor@google.com (Andrew Walbran)
23 | */
24 | public final class Dimensions {
25 |
26 | private final int minCols;
27 | private final int maxCols;
28 | private final int minRows;
29 | private final int maxRows;
30 |
31 | public Dimensions(int minCols, int maxCols, int minRows, int maxRows) {
32 | this.minCols = minCols;
33 | this.maxCols = maxCols;
34 | this.minRows = minRows;
35 | this.maxRows = maxRows;
36 | }
37 |
38 | public int getMinCols() {
39 | return minCols;
40 | }
41 |
42 | public int getMaxCols() {
43 | return maxCols;
44 | }
45 |
46 | public int getMinRows() {
47 | return minRows;
48 | }
49 |
50 | public int getMaxRows() {
51 | return maxRows;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/qrcode/decoder/ErrorCorrectionLevel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.qrcode.decoder;
18 |
19 | /**
20 | *
See ISO 18004:2006, 6.5.1. This enum encapsulates the four error correction levels
21 | * defined by the QR code standard.
22 | *
23 | * @author Sean Owen
24 | */
25 | public enum ErrorCorrectionLevel {
26 |
27 | /** L = ~7% correction */
28 | L(0x01),
29 | /** M = ~15% correction */
30 | M(0x00),
31 | /** Q = ~25% correction */
32 | Q(0x03),
33 | /** H = ~30% correction */
34 | H(0x02);
35 |
36 | private static final ErrorCorrectionLevel[] FOR_BITS = {M, L, H, Q};
37 |
38 | private final int bits;
39 |
40 | ErrorCorrectionLevel(int bits) {
41 | this.bits = bits;
42 | }
43 |
44 | public int getBits() {
45 | return bits;
46 | }
47 |
48 | /**
49 | * @param bits int containing the two bits encoding a QR Code's error correction level
50 | * @return ErrorCorrectionLevel representing the encoded error correction level
51 | */
52 | public static ErrorCorrectionLevel forBits(int bits) {
53 | if (bits < 0 || bits >= FOR_BITS.length) {
54 | throw new IllegalArgumentException();
55 | }
56 | return FOR_BITS[bits];
57 | }
58 |
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/qrcode/decoder/QRCodeDecoderMetaData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.qrcode.decoder;
18 |
19 | import com.google.zxing.ResultPoint;
20 |
21 | /**
22 | * Meta-data container for QR Code decoding. Instances of this class may be used to convey information back to the
23 | * decoding caller. Callers are expected to process this.
24 | *
25 | * @see com.google.zxing.common.DecoderResult#getOther()
26 | */
27 | public final class QRCodeDecoderMetaData {
28 |
29 | private final boolean mirrored;
30 |
31 | QRCodeDecoderMetaData(boolean mirrored) {
32 | this.mirrored = mirrored;
33 | }
34 |
35 | /**
36 | * @return true if the QR Code was mirrored.
37 | */
38 | public boolean isMirrored() {
39 | return mirrored;
40 | }
41 |
42 | /**
43 | * Apply the result points' order correction due to mirroring.
44 | *
45 | * @param points Array of points to apply mirror correction to.
46 | */
47 | public void applyMirroredCorrection(ResultPoint[] points) {
48 | if (!mirrored || points == null || points.length < 3) {
49 | return;
50 | }
51 | ResultPoint bottomLeft = points[0];
52 | points[0] = points[2];
53 | points[2] = bottomLeft;
54 | // No need to 'fix' top-left and alignment pattern.
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/qrcode/detector/AlignmentPattern.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.qrcode.detector;
18 |
19 | import com.google.zxing.ResultPoint;
20 |
21 | /**
22 | *
Encapsulates an alignment pattern, which are the smaller square patterns found in
23 | * all but the simplest QR Codes.
Determines if this alignment pattern "about equals" an alignment pattern at the stated
38 | * position and size -- meaning, it is at nearly the same center with nearly the same size.
39 | */
40 | boolean aboutEquals(float moduleSize, float i, float j) {
41 | if (Math.abs(i - getY()) <= moduleSize && Math.abs(j - getX()) <= moduleSize) {
42 | float moduleSizeDiff = Math.abs(moduleSize - estimatedModuleSize);
43 | return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize;
44 | }
45 | return false;
46 | }
47 |
48 | /**
49 | * Combines this object's current estimate of a finder pattern position and module size
50 | * with a new estimate. It returns a new {@code FinderPattern} containing an average of the two.
51 | */
52 | AlignmentPattern combineEstimate(float i, float j, float newModuleSize) {
53 | float combinedX = (getX() + j) / 2.0f;
54 | float combinedY = (getY() + i) / 2.0f;
55 | float combinedModuleSize = (estimatedModuleSize + newModuleSize) / 2.0f;
56 | return new AlignmentPattern(combinedX, combinedY, combinedModuleSize);
57 | }
58 |
59 | }
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/qrcode/detector/FinderPatternInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.qrcode.detector;
18 |
19 | /**
20 | *
Encapsulates information about finder patterns in an image, including the location of
21 | * the three finder patterns, and their estimated module size.
22 | *
23 | * @author Sean Owen
24 | */
25 | public final class FinderPatternInfo {
26 |
27 | private final FinderPattern bottomLeft;
28 | private final FinderPattern topLeft;
29 | private final FinderPattern topRight;
30 |
31 | public FinderPatternInfo(FinderPattern[] patternCenters) {
32 | this.bottomLeft = patternCenters[0];
33 | this.topLeft = patternCenters[1];
34 | this.topRight = patternCenters[2];
35 | }
36 |
37 | public FinderPattern getBottomLeft() {
38 | return bottomLeft;
39 | }
40 |
41 | public FinderPattern getTopLeft() {
42 | return topLeft;
43 | }
44 |
45 | public FinderPattern getTopRight() {
46 | return topRight;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/qrcode/encoder/BlockPair.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.qrcode.encoder;
18 |
19 | final class BlockPair {
20 |
21 | private final byte[] dataBytes;
22 | private final byte[] errorCorrectionBytes;
23 |
24 | BlockPair(byte[] data, byte[] errorCorrection) {
25 | dataBytes = data;
26 | errorCorrectionBytes = errorCorrection;
27 | }
28 |
29 | public byte[] getDataBytes() {
30 | return dataBytes;
31 | }
32 |
33 | public byte[] getErrorCorrectionBytes() {
34 | return errorCorrectionBytes;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/AbstractDoCoMoResultParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | /**
20 | *
Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
25 | * on exception-based mechanisms during parsing.
26 | *
27 | * @author Sean Owen
28 | */
29 | abstract class AbstractDoCoMoResultParser extends ResultParser {
30 |
31 | static String[] matchDoCoMoPrefixedField(String prefix, String rawText) {
32 | return matchPrefixedField(prefix, rawText, ';', true);
33 | }
34 |
35 | static String matchSingleDoCoMoPrefixedField(String prefix, String rawText, boolean trim) {
36 | return matchSinglePrefixedField(prefix, rawText, ';', trim);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/BookmarkDoCoMoResultParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | import com.google.zxing.Result;
20 |
21 | /**
22 | * @author Sean Owen
23 | */
24 | public final class BookmarkDoCoMoResultParser extends AbstractDoCoMoResultParser {
25 |
26 | @Override
27 | public URIParsedResult parse(Result result) {
28 | String rawText = result.getText();
29 | if (!rawText.startsWith("MEBKM:")) {
30 | return null;
31 | }
32 | String title = matchSingleDoCoMoPrefixedField("TITLE:", rawText, true);
33 | String[] rawUri = matchDoCoMoPrefixedField("URL:", rawText);
34 | if (rawUri == null) {
35 | return null;
36 | }
37 | String uri = rawUri[0];
38 | return URIResultParser.isBasicallyValidURI(uri) ? new URIParsedResult(uri, title) : null;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/EmailAddressParsedResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | /**
20 | * Represents a parsed result that encodes an email message including recipients, subject
21 | * and body text.
22 | *
23 | * @author Sean Owen
24 | */
25 | public final class EmailAddressParsedResult extends ParsedResult {
26 |
27 | private final String[] tos;
28 | private final String[] ccs;
29 | private final String[] bccs;
30 | private final String subject;
31 | private final String body;
32 |
33 | EmailAddressParsedResult(String to) {
34 | this(new String[] {to}, null, null, null, null);
35 | }
36 |
37 | EmailAddressParsedResult(String[] tos,
38 | String[] ccs,
39 | String[] bccs,
40 | String subject,
41 | String body) {
42 | super(ParsedResultType.EMAIL_ADDRESS);
43 | this.tos = tos;
44 | this.ccs = ccs;
45 | this.bccs = bccs;
46 | this.subject = subject;
47 | this.body = body;
48 | }
49 |
50 | /**
51 | * @return first elements of {@link #getTos()} or {@code null} if none
52 | * @deprecated use {@link #getTos()}
53 | */
54 | @Deprecated
55 | public String getEmailAddress() {
56 | return tos == null || tos.length == 0 ? null : tos[0];
57 | }
58 |
59 | public String[] getTos() {
60 | return tos;
61 | }
62 |
63 | public String[] getCCs() {
64 | return ccs;
65 | }
66 |
67 | public String[] getBCCs() {
68 | return bccs;
69 | }
70 |
71 | public String getSubject() {
72 | return subject;
73 | }
74 |
75 | public String getBody() {
76 | return body;
77 | }
78 |
79 | /**
80 | * @return "mailto:"
81 | * @deprecated without replacement
82 | */
83 | @Deprecated
84 | public String getMailtoURI() {
85 | return "mailto:";
86 | }
87 |
88 | @Override
89 | public String getDisplayResult() {
90 | StringBuilder result = new StringBuilder(30);
91 | maybeAppend(tos, result);
92 | maybeAppend(ccs, result);
93 | maybeAppend(bccs, result);
94 | maybeAppend(subject, result);
95 | maybeAppend(body, result);
96 | return result.toString();
97 | }
98 |
99 | }
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/EmailDoCoMoResultParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | import com.google.zxing.Result;
20 |
21 | import java.util.regex.Pattern;
22 |
23 | /**
24 | * Implements the "MATMSG" email message entry format.
25 | *
26 | * Supported keys: TO, SUB, BODY
27 | *
28 | * @author Sean Owen
29 | */
30 | public final class EmailDoCoMoResultParser extends AbstractDoCoMoResultParser {
31 |
32 | private static final Pattern ATEXT_ALPHANUMERIC = Pattern.compile("[a-zA-Z0-9@.!#$%&'*+\\-/=?^_`{|}~]+");
33 |
34 | @Override
35 | public EmailAddressParsedResult parse(Result result) {
36 | String rawText = getMassagedText(result);
37 | if (!rawText.startsWith("MATMSG:")) {
38 | return null;
39 | }
40 | String[] tos = matchDoCoMoPrefixedField("TO:", rawText);
41 | if (tos == null) {
42 | return null;
43 | }
44 | for (String to : tos) {
45 | if (!isBasicallyValidEmailAddress(to)) {
46 | return null;
47 | }
48 | }
49 | String subject = matchSingleDoCoMoPrefixedField("SUB:", rawText, false);
50 | String body = matchSingleDoCoMoPrefixedField("BODY:", rawText, false);
51 | return new EmailAddressParsedResult(tos, null, null, subject, body);
52 | }
53 |
54 | /**
55 | * This implements only the most basic checking for an email address's validity -- that it contains
56 | * an '@' and contains no characters disallowed by RFC 2822. This is an overly lenient definition of
57 | * validity. We want to generally be lenient here since this class is only intended to encapsulate what's
58 | * in a barcode, not "judge" it.
59 | */
60 | static boolean isBasicallyValidEmailAddress(String email) {
61 | return email != null && ATEXT_ALPHANUMERIC.matcher(email).matches() && email.indexOf('@') >= 0;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/GeoResultParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | import com.google.zxing.Result;
20 |
21 | import java.util.regex.Matcher;
22 | import java.util.regex.Pattern;
23 |
24 | /**
25 | * Parses a "geo:" URI result, which specifies a location on the surface of
26 | * the Earth as well as an optional altitude above the surface. See
27 | *
28 | * http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00.
29 | *
30 | * @author Sean Owen
31 | */
32 | public final class GeoResultParser extends ResultParser {
33 |
34 | private static final Pattern GEO_URL_PATTERN =
35 | Pattern.compile("geo:([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9.]+))?(?:\\?(.*))?", Pattern.CASE_INSENSITIVE);
36 |
37 | @Override
38 | public GeoParsedResult parse(Result result) {
39 | CharSequence rawText = getMassagedText(result);
40 | Matcher matcher = GEO_URL_PATTERN.matcher(rawText);
41 | if (!matcher.matches()) {
42 | return null;
43 | }
44 |
45 | String query = matcher.group(4);
46 |
47 | double latitude;
48 | double longitude;
49 | double altitude;
50 | try {
51 | latitude = Double.parseDouble(matcher.group(1));
52 | if (latitude > 90.0 || latitude < -90.0) {
53 | return null;
54 | }
55 | longitude = Double.parseDouble(matcher.group(2));
56 | if (longitude > 180.0 || longitude < -180.0) {
57 | return null;
58 | }
59 | if (matcher.group(3) == null) {
60 | altitude = 0.0;
61 | } else {
62 | altitude = Double.parseDouble(matcher.group(3));
63 | if (altitude < 0.0) {
64 | return null;
65 | }
66 | }
67 | } catch (NumberFormatException ignored) {
68 | return null;
69 | }
70 | return new GeoParsedResult(latitude, longitude, altitude, query);
71 | }
72 |
73 | }
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/ISBNParsedResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | /**
20 | * Represents a parsed result that encodes a product ISBN number.
21 | *
22 | * @author jbreiden@google.com (Jeff Breidenbach)
23 | */
24 | public final class ISBNParsedResult extends ParsedResult {
25 |
26 | private final String isbn;
27 |
28 | ISBNParsedResult(String isbn) {
29 | super(ParsedResultType.ISBN);
30 | this.isbn = isbn;
31 | }
32 |
33 | public String getISBN() {
34 | return isbn;
35 | }
36 |
37 | @Override
38 | public String getDisplayResult() {
39 | return isbn;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/ISBNResultParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | import com.google.zxing.BarcodeFormat;
20 | import com.google.zxing.Result;
21 |
22 | /**
23 | * Parses strings of digits that represent a ISBN.
24 | *
25 | * @author jbreiden@google.com (Jeff Breidenbach)
26 | */
27 | public final class ISBNResultParser extends ResultParser {
28 |
29 | /**
30 | * See ISBN-13 For Dummies
31 | */
32 | @Override
33 | public ISBNParsedResult parse(Result result) {
34 | BarcodeFormat format = result.getBarcodeFormat();
35 | if (format != BarcodeFormat.EAN_13) {
36 | return null;
37 | }
38 | String rawText = getMassagedText(result);
39 | int length = rawText.length();
40 | if (length != 13) {
41 | return null;
42 | }
43 | if (!rawText.startsWith("978") && !rawText.startsWith("979")) {
44 | return null;
45 | }
46 |
47 | return new ISBNParsedResult(rawText);
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/ParsedResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | /**
20 | *
Abstract class representing the result of decoding a barcode, as more than
21 | * a String -- as some type of structured data. This might be a subclass which represents
22 | * a URL, or an e-mail address. {@link ResultParser#parseResult(com.google.zxing.Result)} will turn a raw
23 | * decoded string into the most appropriate type of structured representation.
24 | *
25 | *
Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
26 | * on exception-based mechanisms during parsing.
27 | *
28 | * @author Sean Owen
29 | */
30 | public abstract class ParsedResult {
31 |
32 | private final ParsedResultType type;
33 |
34 | protected ParsedResult(ParsedResultType type) {
35 | this.type = type;
36 | }
37 |
38 | public final ParsedResultType getType() {
39 | return type;
40 | }
41 |
42 | public abstract String getDisplayResult();
43 |
44 | @Override
45 | public final String toString() {
46 | return getDisplayResult();
47 | }
48 |
49 | public static void maybeAppend(String value, StringBuilder result) {
50 | if (value != null && !value.isEmpty()) {
51 | // Don't add a newline before the first value
52 | if (result.length() > 0) {
53 | result.append('\n');
54 | }
55 | result.append(value);
56 | }
57 | }
58 |
59 | public static void maybeAppend(String[] values, StringBuilder result) {
60 | if (values != null) {
61 | for (String value : values) {
62 | maybeAppend(value, result);
63 | }
64 | }
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/ParsedResultType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | /**
20 | * Represents the type of data encoded by a barcode -- from plain text, to a
21 | * URI, to an e-mail address, etc.
22 | *
23 | * @author Sean Owen
24 | */
25 | public enum ParsedResultType {
26 |
27 | ADDRESSBOOK,
28 | EMAIL_ADDRESS,
29 | PRODUCT,
30 | URI,
31 | TEXT,
32 | GEO,
33 | TEL,
34 | SMS,
35 | CALENDAR,
36 | WIFI,
37 | ISBN,
38 | VIN,
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/ProductParsedResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | /**
20 | * Represents a parsed result that encodes a product by an identifier of some kind.
21 | *
22 | * @author dswitkin@google.com (Daniel Switkin)
23 | */
24 | public final class ProductParsedResult extends ParsedResult {
25 |
26 | private final String productID;
27 | private final String normalizedProductID;
28 |
29 | ProductParsedResult(String productID) {
30 | this(productID, productID);
31 | }
32 |
33 | ProductParsedResult(String productID, String normalizedProductID) {
34 | super(ParsedResultType.PRODUCT);
35 | this.productID = productID;
36 | this.normalizedProductID = normalizedProductID;
37 | }
38 |
39 | public String getProductID() {
40 | return productID;
41 | }
42 |
43 | public String getNormalizedProductID() {
44 | return normalizedProductID;
45 | }
46 |
47 | @Override
48 | public String getDisplayResult() {
49 | return productID;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/ProductResultParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | import com.google.zxing.BarcodeFormat;
20 | import com.google.zxing.Result;
21 | import com.google.zxing.oned.UPCEReader;
22 |
23 | /**
24 | * Parses strings of digits that represent a UPC code.
25 | *
26 | * @author dswitkin@google.com (Daniel Switkin)
27 | */
28 | public final class ProductResultParser extends ResultParser {
29 |
30 | // Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes.
31 | @Override
32 | public ProductParsedResult parse(Result result) {
33 | BarcodeFormat format = result.getBarcodeFormat();
34 | if (!(format == BarcodeFormat.UPC_A || format == BarcodeFormat.UPC_E ||
35 | format == BarcodeFormat.EAN_8 || format == BarcodeFormat.EAN_13)) {
36 | return null;
37 | }
38 | String rawText = getMassagedText(result);
39 | if (!isStringOfDigits(rawText, rawText.length())) {
40 | return null;
41 | }
42 | // Not actually checking the checksum again here
43 |
44 | String normalizedProductID;
45 | // Expand UPC-E for purposes of searching
46 | if (format == BarcodeFormat.UPC_E && rawText.length() == 8) {
47 | normalizedProductID = UPCEReader.convertUPCEtoUPCA(rawText);
48 | } else {
49 | normalizedProductID = rawText;
50 | }
51 |
52 | return new ProductParsedResult(rawText, normalizedProductID);
53 | }
54 |
55 | }
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/SMSTOMMSTOResultParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | import com.google.zxing.Result;
20 |
21 | /**
22 | *
Parses an "smsto:" URI result, whose format is not standardized but appears to be like:
23 | * {@code smsto:number(:body)}.
24 | *
25 | *
This actually also parses URIs starting with "smsto:", "mmsto:", "SMSTO:", and
26 | * "MMSTO:", and treats them all the same way, and effectively converts them to an "sms:" URI
27 | * for purposes of forwarding to the platform.
28 | *
29 | * @author Sean Owen
30 | */
31 | public final class SMSTOMMSTOResultParser extends ResultParser {
32 |
33 | @Override
34 | public SMSParsedResult parse(Result result) {
35 | String rawText = getMassagedText(result);
36 | if (!(rawText.startsWith("smsto:") || rawText.startsWith("SMSTO:") ||
37 | rawText.startsWith("mmsto:") || rawText.startsWith("MMSTO:"))) {
38 | return null;
39 | }
40 | // Thanks to dominik.wild for suggesting this enhancement to support
41 | // smsto:number:body URIs
42 | String number = rawText.substring(6);
43 | String body = null;
44 | int bodyStart = number.indexOf(':');
45 | if (bodyStart >= 0) {
46 | body = number.substring(bodyStart + 1);
47 | number = number.substring(0, bodyStart);
48 | }
49 | return new SMSParsedResult(number, null, null, body);
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/SMTPResultParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | import com.google.zxing.Result;
20 |
21 | /**
22 | *
Parses an "smtp:" URI result, whose format is not standardized but appears to be like:
23 | * {@code smtp[:subject[:body]]}.
24 | *
25 | * @author Sean Owen
26 | */
27 | public final class SMTPResultParser extends ResultParser {
28 |
29 | @Override
30 | public EmailAddressParsedResult parse(Result result) {
31 | String rawText = getMassagedText(result);
32 | if (!(rawText.startsWith("smtp:") || rawText.startsWith("SMTP:"))) {
33 | return null;
34 | }
35 | String emailAddress = rawText.substring(5);
36 | String subject = null;
37 | String body = null;
38 | int colon = emailAddress.indexOf(':');
39 | if (colon >= 0) {
40 | subject = emailAddress.substring(colon + 1);
41 | emailAddress = emailAddress.substring(0, colon);
42 | colon = subject.indexOf(':');
43 | if (colon >= 0) {
44 | body = subject.substring(colon + 1);
45 | subject = subject.substring(0, colon);
46 | }
47 | }
48 | return new EmailAddressParsedResult(new String[] {emailAddress},
49 | null,
50 | null,
51 | subject,
52 | body);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/TelParsedResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | /**
20 | * Represents a parsed result that encodes a telephone number.
21 | *
22 | * @author Sean Owen
23 | */
24 | public final class TelParsedResult extends ParsedResult {
25 |
26 | private final String number;
27 | private final String telURI;
28 | private final String title;
29 |
30 | public TelParsedResult(String number, String telURI, String title) {
31 | super(ParsedResultType.TEL);
32 | this.number = number;
33 | this.telURI = telURI;
34 | this.title = title;
35 | }
36 |
37 | public String getNumber() {
38 | return number;
39 | }
40 |
41 | public String getTelURI() {
42 | return telURI;
43 | }
44 |
45 | public String getTitle() {
46 | return title;
47 | }
48 |
49 | @Override
50 | public String getDisplayResult() {
51 | StringBuilder result = new StringBuilder(20);
52 | maybeAppend(number, result);
53 | maybeAppend(title, result);
54 | return result.toString();
55 | }
56 |
57 | }
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/TelResultParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | import com.google.zxing.Result;
20 |
21 | /**
22 | * Parses a "tel:" URI result, which specifies a phone number.
23 | *
24 | * @author Sean Owen
25 | */
26 | public final class TelResultParser extends ResultParser {
27 |
28 | @Override
29 | public TelParsedResult parse(Result result) {
30 | String rawText = getMassagedText(result);
31 | if (!rawText.startsWith("tel:") && !rawText.startsWith("TEL:")) {
32 | return null;
33 | }
34 | // Normalize "TEL:" to "tel:"
35 | String telURI = rawText.startsWith("TEL:") ? "tel:" + rawText.substring(4) : rawText;
36 | // Drop tel, query portion
37 | int queryStart = rawText.indexOf('?', 4);
38 | String number = queryStart < 0 ? rawText.substring(4) : rawText.substring(4, queryStart);
39 | return new TelParsedResult(number, telURI, null);
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/TextParsedResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | /**
20 | * A simple result type encapsulating a string that has no further
21 | * interpretation.
22 | *
23 | * @author Sean Owen
24 | */
25 | public final class TextParsedResult extends ParsedResult {
26 |
27 | private final String text;
28 | private final String language;
29 |
30 | public TextParsedResult(String text, String language) {
31 | super(ParsedResultType.TEXT);
32 | this.text = text;
33 | this.language = language;
34 | }
35 |
36 | public String getText() {
37 | return text;
38 | }
39 |
40 | public String getLanguage() {
41 | return language;
42 | }
43 |
44 | @Override
45 | public String getDisplayResult() {
46 | return text;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/URIParsedResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | /**
20 | * A simple result type encapsulating a URI that has no further interpretation.
21 | *
22 | * @author Sean Owen
23 | */
24 | public final class URIParsedResult extends ParsedResult {
25 |
26 | private final String uri;
27 | private final String title;
28 |
29 | public URIParsedResult(String uri, String title) {
30 | super(ParsedResultType.URI);
31 | this.uri = massageURI(uri);
32 | this.title = title;
33 | }
34 |
35 | public String getURI() {
36 | return uri;
37 | }
38 |
39 | public String getTitle() {
40 | return title;
41 | }
42 |
43 | /**
44 | * @return true if the URI contains suspicious patterns that may suggest it intends to
45 | * mislead the user about its true nature
46 | * @deprecated see {@link URIResultParser#isPossiblyMaliciousURI(String)}
47 | */
48 | @Deprecated
49 | public boolean isPossiblyMaliciousURI() {
50 | return URIResultParser.isPossiblyMaliciousURI(uri);
51 | }
52 |
53 | @Override
54 | public String getDisplayResult() {
55 | StringBuilder result = new StringBuilder(30);
56 | maybeAppend(title, result);
57 | maybeAppend(uri, result);
58 | return result.toString();
59 | }
60 |
61 | /**
62 | * Transforms a string that represents a URI into something more proper, by adding or canonicalizing
63 | * the protocol.
64 | */
65 | private static String massageURI(String uri) {
66 | uri = uri.trim();
67 | int protocolEnd = uri.indexOf(':');
68 | if (protocolEnd < 0 || isColonFollowedByPortNumber(uri, protocolEnd)) {
69 | // No protocol, or found a colon, but it looks like it is after the host, so the protocol is still missing,
70 | // so assume http
71 | uri = "http://" + uri;
72 | }
73 | return uri;
74 | }
75 |
76 | private static boolean isColonFollowedByPortNumber(String uri, int protocolEnd) {
77 | int start = protocolEnd + 1;
78 | int nextSlash = uri.indexOf('/', start);
79 | if (nextSlash < 0) {
80 | nextSlash = uri.length();
81 | }
82 | return ResultParser.isSubstringOfDigits(uri, start, nextSlash - start);
83 | }
84 |
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/com/google/zxing/result/URLTOResultParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.result;
18 |
19 | import com.google.zxing.Result;
20 |
21 | /**
22 | * Parses the "URLTO" result format, which is of the form "URLTO:[title]:[url]".
23 | * This seems to be used sometimes, but I am not able to find documentation
24 | * on its origin or official format?
25 | *
26 | * @author Sean Owen
27 | */
28 | public final class URLTOResultParser extends ResultParser {
29 |
30 | @Override
31 | public URIParsedResult parse(Result result) {
32 | String rawText = getMassagedText(result);
33 | if (!rawText.startsWith("urlto:") && !rawText.startsWith("URLTO:")) {
34 | return null;
35 | }
36 | int titleEnd = rawText.indexOf(':', 6);
37 | if (titleEnd < 0) {
38 | return null;
39 | }
40 | String title = titleEnd <= 6 ? null : rawText.substring(6, titleEnd);
41 | String uri = rawText.substring(titleEnd + 1);
42 | return new URIParsedResult(uri, title);
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/org/dync/zxinglibrary/callback/ScanListener.java:
--------------------------------------------------------------------------------
1 | package org.dync.zxinglibrary.callback;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.google.zxing.Result;
6 | import com.google.zxing.ResultPoint;
7 |
8 | public interface ScanListener {
9 | /**
10 | * 返回扫描结果
11 | * @param rawResult 结果对象
12 | * @param bitmap 存放了截图,或者是空的
13 | */
14 | public void scanResult(Result rawResult, Bitmap bitmap);
15 | /**
16 | * 扫描抛出的异常
17 | * @param e
18 | */
19 | public void scanError(Exception e);
20 |
21 | public void foundPossibleResultPoint(ResultPoint point);
22 | }
23 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/org/dync/zxinglibrary/camera/FrontLightMode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dync.zxinglibrary.camera;
18 |
19 | import android.content.SharedPreferences;
20 |
21 | import org.dync.zxinglibrary.utils.PreferencesActivity;
22 |
23 | /**
24 | * Enumerates settings of the preference controlling the front light.
25 | */
26 | public enum FrontLightMode {
27 |
28 | /** Always on. */
29 | ON,
30 | /** On only when ambient light is low. */
31 | AUTO,
32 | /** Always off. */
33 | OFF;
34 |
35 | private static FrontLightMode parse(String modeString) {
36 | return modeString == null ? OFF : valueOf(modeString);
37 | }
38 |
39 | public static FrontLightMode readPref(SharedPreferences sharedPrefs) {
40 | return parse(sharedPrefs.getString(PreferencesActivity.KEY_FRONT_LIGHT_MODE, OFF.toString()));
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/org/dync/zxinglibrary/camera/PreviewCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dync.zxinglibrary.camera;
18 |
19 | import android.graphics.Point;
20 | import android.hardware.Camera;
21 | import android.os.Handler;
22 | import android.os.Message;
23 |
24 | @SuppressWarnings("deprecation") // camera APIs
25 | final class PreviewCallback implements Camera.PreviewCallback {
26 |
27 | private final CameraConfigurationManager configManager;
28 | private Handler previewHandler;
29 | private int previewMessage;
30 |
31 | PreviewCallback(CameraConfigurationManager configManager) {
32 | this.configManager = configManager;
33 | }
34 |
35 | void setHandler(Handler previewHandler, int previewMessage) {
36 | this.previewHandler = previewHandler;
37 | this.previewMessage = previewMessage;
38 | }
39 |
40 | @Override
41 | public void onPreviewFrame(byte[] data, Camera camera) {
42 | Point cameraResolution = configManager.getCameraResolution();
43 | Handler thePreviewHandler = previewHandler;
44 | if (cameraResolution != null && thePreviewHandler != null) {
45 | Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x,
46 | cameraResolution.y, data);
47 | message.sendToTarget();
48 | previewHandler = null;
49 | }
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/org/dync/zxinglibrary/camera/open/CameraFacing.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dync.zxinglibrary.camera.open;
18 |
19 | /**
20 | * Enumeration of directions a camera may face: front or back.
21 | */
22 | public enum CameraFacing {
23 |
24 | BACK, // must be value 0!
25 | FRONT, // must be value 1!
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/org/dync/zxinglibrary/camera/open/OpenCamera.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.dync.zxinglibrary.camera.open;
18 |
19 | import android.hardware.Camera;
20 |
21 | /**
22 | * Represents an open {@link Camera} and its metadata, like facing direction and orientation.
23 | */
24 | @SuppressWarnings("deprecation") // camera APIs
25 | public final class OpenCamera {
26 |
27 | private final int index;
28 | private final Camera camera;
29 | private final CameraFacing facing;
30 | private final int orientation;
31 |
32 | public OpenCamera(int index, Camera camera, CameraFacing facing, int orientation) {
33 | this.index = index;
34 | this.camera = camera;
35 | this.facing = facing;
36 | this.orientation = orientation;
37 | }
38 |
39 | public Camera getCamera() {
40 | return camera;
41 | }
42 |
43 | public CameraFacing getFacing() {
44 | return facing;
45 | }
46 |
47 | public int getOrientation() {
48 | return orientation;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "Camera #" + index + " : " + facing + ',' + orientation;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/java/org/dync/zxinglibrary/decod/PhotoScanHandler.java:
--------------------------------------------------------------------------------
1 | package org.dync.zxinglibrary.decod;
2 |
3 | import android.os.Handler;
4 | import android.os.Message;
5 |
6 | import com.google.zxing.Result;
7 |
8 | import org.dync.zxinglibrary.ScanManager;
9 |
10 | public class PhotoScanHandler extends Handler {
11 | public final static int PHOTODECODEERROR = 0;
12 | public final static int PHOTODECODEOK = 1;
13 | ScanManager scanManager;
14 | public PhotoScanHandler(ScanManager scanManager) {
15 | this.scanManager = scanManager;
16 | }
17 | @Override
18 | public void handleMessage(Message message) {
19 | switch (message.what) {
20 | case PHOTODECODEERROR:
21 | scanManager.handleDecodeError((Exception)message.obj);
22 | break;
23 | case PHOTODECODEOK:
24 | scanManager.handleDecode((Result) message.obj, null, 1.0f);
25 | break;
26 | default:
27 | break;
28 | }
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/res/raw/beep.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DyncKathline/ZxingScan/e87cd33c33d6a2d3779498a80e7ee33cebad28aa/zxinglibrary/src/main/res/raw/beep.ogg
--------------------------------------------------------------------------------
/zxinglibrary/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | ON
20 | AUTO
21 | OFF
22 |
23 |
24 | @string/preferences_front_light_on
25 | @string/preferences_front_light_auto
26 | @string/preferences_front_light_off
27 |
28 |
29 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | #ff000000
19 | #ffffffff
20 | #c0ffbd21
21 | #ffc0c0c0
22 | #c099cc00
23 | #ffffffff
24 | #b0000000
25 | #ffffffff
26 | #00000000
27 | #ffcc0000
28 | #60000000
29 |
30 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | 8dip
19 | 4dip
20 |
21 |
--------------------------------------------------------------------------------
/zxinglibrary/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------