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
17package eu.siacs.conversations.utils.zxing;
18
19/**
20 * <p>Encapsulates the result of a barcode scan invoked through {@link IntentIntegrator}.</p>
21 *
22 * @author Sean Owen
23 */
24public final class IntentResult {
25
26 private final String contents;
27 private final String formatName;
28 private final byte[] rawBytes;
29 private final Integer orientation;
30 private final String errorCorrectionLevel;
31
32 IntentResult() {
33 this(null, null, null, null, null);
34 }
35
36 IntentResult(String contents,
37 String formatName,
38 byte[] rawBytes,
39 Integer orientation,
40 String errorCorrectionLevel) {
41 this.contents = contents;
42 this.formatName = formatName;
43 this.rawBytes = rawBytes;
44 this.orientation = orientation;
45 this.errorCorrectionLevel = errorCorrectionLevel;
46 }
47
48 /**
49 * @return raw content of barcode
50 */
51 public String getContents() {
52 return contents;
53 }
54
55 /**
56 * @return name of format, like "QR_CODE", "UPC_A". See {@code BarcodeFormat} for more format names.
57 */
58 public String getFormatName() {
59 return formatName;
60 }
61
62 /**
63 * @return raw bytes of the barcode content, if applicable, or null otherwise
64 */
65 public byte[] getRawBytes() {
66 return rawBytes;
67 }
68
69 /**
70 * @return rotation of the image, in degrees, which resulted in a successful scan. May be null.
71 */
72 public Integer getOrientation() {
73 return orientation;
74 }
75
76 /**
77 * @return name of the error correction level used in the barcode, if applicable
78 */
79 public String getErrorCorrectionLevel() {
80 return errorCorrectionLevel;
81 }
82
83 @Override
84 public String toString() {
85 int rawBytesLength = rawBytes == null ? 0 : rawBytes.length;
86 return "Format: " + formatName + '\n' +
87 "Contents: " + contents + '\n' +
88 "Raw bytes: (" + rawBytesLength + " bytes)\n" +
89 "Orientation: " + orientation + '\n' +
90 "EC level: " + errorCorrectionLevel + '\n';
91 }
92
93}