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 | -------------------------------------------------------------------------------- /zxinglite/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 | -------------------------------------------------------------------------------- /zxinglite/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 | -------------------------------------------------------------------------------- /zxinglite/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 | -------------------------------------------------------------------------------- /zxinglite/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 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/android/AnimeViewCallback.java: -------------------------------------------------------------------------------- 1 | package com.google.zxing.client.android; 2 | 3 | import com.google.zxing.ResultPoint; 4 | import com.google.zxing.client.android.camera.CameraManager; 5 | 6 | /** 7 | * 获取点状 8 | * Created by weixing9920@163.com on 2017/10/15. 9 | */ 10 | 11 | public interface AnimeViewCallback { 12 | 13 | void addPossibleResultPoint(ResultPoint point); 14 | 15 | void setCameraManager(CameraManager cameraManager); 16 | 17 | void drawViewfinder(); 18 | } 19 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/android/Ids.java: -------------------------------------------------------------------------------- 1 | package com.google.zxing.client.android; 2 | 3 | /** 4 | * Created by yangxixi on 16/11/21. 5 | */ 6 | 7 | public class Ids { 8 | public static final int decode = 1001; 9 | public static final int decode_failed = 1002; 10 | public static final int decode_succeeded = 1003; 11 | public static final int launch_product_query = 1004; 12 | public static final int quit = 1005; 13 | public static final int restart_preview = 1006; 14 | public static final int return_scan_result = 1007; 15 | } 16 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/android/IntentSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 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.client.android; 18 | 19 | public enum IntentSource { 20 | 21 | NATIVE_APP_INTENT, 22 | PRODUCT_SEARCH_LINK, 23 | ZXING_LINK, 24 | NONE 25 | 26 | } 27 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/android/ViewfinderResultPointCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 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.client.android; 18 | 19 | import com.google.zxing.ResultPoint; 20 | import com.google.zxing.ResultPointCallback; 21 | 22 | final class ViewfinderResultPointCallback implements ResultPointCallback { 23 | 24 | private ViewfinderView viewfinderView; 25 | private AnimeViewCallback animeViewCallback = null; 26 | 27 | ViewfinderResultPointCallback(ViewfinderView viewfinderView) { 28 | this.viewfinderView = viewfinderView; 29 | } 30 | 31 | ViewfinderResultPointCallback(AnimeViewCallback animeViewCallback) { 32 | this.animeViewCallback = animeViewCallback; 33 | } 34 | 35 | @Override 36 | public void foundPossibleResultPoint(ResultPoint point) { 37 | if(animeViewCallback == null) 38 | return; 39 | animeViewCallback.addPossibleResultPoint(point); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/android/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 com.google.zxing.client.android.camera; 18 | 19 | import android.content.SharedPreferences; 20 | import com.google.zxing.client.android.PreferencesActivity; 21 | 22 | /** 23 | * Enumerates settings of the preference controlling the front light. 24 | */ 25 | public enum FrontLightMode { 26 | 27 | /** Always on. */ 28 | ON, 29 | /** On only when ambient light is low. */ 30 | AUTO, 31 | /** Always off. */ 32 | OFF; 33 | 34 | private static FrontLightMode parse(String modeString) { 35 | return modeString == null ? OFF : valueOf(modeString); 36 | } 37 | 38 | public static FrontLightMode readPref(SharedPreferences sharedPrefs) { 39 | return parse(sharedPrefs.getString(PreferencesActivity.KEY_FRONT_LIGHT_MODE, OFF.toString())); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/android/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 com.google.zxing.client.android.camera; 18 | 19 | import android.graphics.Point; 20 | import android.hardware.Camera; 21 | import android.os.Handler; 22 | import android.os.Message; 23 | import android.util.Log; 24 | 25 | final class PreviewCallback implements Camera.PreviewCallback { 26 | 27 | private static final String TAG = PreviewCallback.class.getSimpleName(); 28 | 29 | private final CameraConfigurationManager configManager; 30 | private Handler previewHandler; 31 | private int previewMessage; 32 | 33 | PreviewCallback(CameraConfigurationManager configManager) { 34 | this.configManager = configManager; 35 | } 36 | 37 | void setHandler(Handler previewHandler, int previewMessage) { 38 | this.previewHandler = previewHandler; 39 | this.previewMessage = previewMessage; 40 | } 41 | 42 | @Override 43 | public void onPreviewFrame(byte[] data, Camera camera) { 44 | Point cameraResolution = configManager.getCameraResolution(); 45 | Handler thePreviewHandler = previewHandler; 46 | if (cameraResolution != null && thePreviewHandler != null) { 47 | Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x, 48 | cameraResolution.y, data); 49 | message.sendToTarget(); 50 | previewHandler = null; 51 | } else { 52 | Log.d(TAG, "Got preview callback, but no handler or resolution available"); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/android/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 com.google.zxing.client.android.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 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/android/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 com.google.zxing.client.android.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 | public final class OpenCamera { 25 | 26 | private final int index; 27 | private final Camera camera; 28 | private final CameraFacing facing; 29 | private final int orientation; 30 | 31 | public OpenCamera(int index, Camera camera, CameraFacing facing, int orientation) { 32 | this.index = index; 33 | this.camera = camera; 34 | this.facing = facing; 35 | this.orientation = orientation; 36 | } 37 | 38 | public Camera getCamera() { 39 | return camera; 40 | } 41 | 42 | public CameraFacing getFacing() { 43 | return facing; 44 | } 45 | 46 | public int getOrientation() { 47 | return orientation; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "Camera #" + index + " : " + facing + ',' + orientation; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.result; 18 | 19 | /** 20 | *See 21 | * 22 | * DoCoMo's documentation about the result types represented by subclasses of this class.
23 | * 24 | *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, boolean trim) { 32 | return matchPrefixedField(prefix, rawText, ';', trim); 33 | } 34 | 35 | static String matchSingleDoCoMoPrefixedField(String prefix, String rawText, boolean trim) { 36 | return matchSinglePrefixedField(prefix, rawText, ';', trim); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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, true); 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 | } -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | } -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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, true); 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 | } -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | } -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | } -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | } -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | } -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | } -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/result/URIResultParser.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.client.result; 18 | 19 | import com.google.zxing.Result; 20 | 21 | import java.util.regex.Matcher; 22 | import java.util.regex.Pattern; 23 | 24 | /** 25 | * Tries to parse results that are a URI of some kind. 26 | * 27 | * @author Sean Owen 28 | */ 29 | public final class URIResultParser extends ResultParser { 30 | 31 | // See http://www.ietf.org/rfc/rfc2396.txt 32 | private static final Pattern URL_WITH_PROTOCOL_PATTERN = Pattern.compile("[a-zA-Z][a-zA-Z0-9+-.]+:"); 33 | private static final Pattern URL_WITHOUT_PROTOCOL_PATTERN = Pattern.compile( 34 | "([a-zA-Z0-9\\-]+\\.){1,6}[a-zA-Z]{2,}" + // host name elements; allow up to say 6 domain elements 35 | "(:\\d{1,5})?" + // maybe port 36 | "(/|\\?|$)"); // query, path or nothing 37 | 38 | @Override 39 | public URIParsedResult parse(Result result) { 40 | String rawText = getMassagedText(result); 41 | // We specifically handle the odd "URL" scheme here for simplicity and add "URI" for fun 42 | // Assume anything starting this way really means to be a URI 43 | if (rawText.startsWith("URL:") || rawText.startsWith("URI:")) { 44 | return new URIParsedResult(rawText.substring(4).trim(), null); 45 | } 46 | rawText = rawText.trim(); 47 | return isBasicallyValidURI(rawText) ? new URIParsedResult(rawText, null) : null; 48 | } 49 | 50 | static boolean isBasicallyValidURI(String uri) { 51 | if (uri.contains(" ")) { 52 | // Quick hack check for a common case 53 | return false; 54 | } 55 | Matcher m = URL_WITH_PROTOCOL_PATTERN.matcher(uri); 56 | if (m.find() && m.start() == 0) { // match at start only 57 | return true; 58 | } 59 | m = URL_WITHOUT_PROTOCOL_PATTERN.matcher(uri); 60 | return m.find() && m.start() == 0; 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/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.client.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 | } -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/result/WifiParsedResult.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.client.result; 18 | 19 | /** 20 | * Represents a parsed result that encodes wifi network information, like SSID and password. 21 | * 22 | * @author Vikram Aggarwal 23 | */ 24 | public final class WifiParsedResult extends ParsedResult { 25 | 26 | private final String ssid; 27 | private final String networkEncryption; 28 | private final String password; 29 | private final boolean hidden; 30 | 31 | public WifiParsedResult(String networkEncryption, String ssid, String password) { 32 | this(networkEncryption, ssid, password, false); 33 | } 34 | 35 | public WifiParsedResult(String networkEncryption, String ssid, String password, boolean hidden) { 36 | super(ParsedResultType.WIFI); 37 | this.ssid = ssid; 38 | this.networkEncryption = networkEncryption; 39 | this.password = password; 40 | this.hidden = hidden; 41 | } 42 | 43 | public String getSsid() { 44 | return ssid; 45 | } 46 | 47 | public String getNetworkEncryption() { 48 | return networkEncryption; 49 | } 50 | 51 | public String getPassword() { 52 | return password; 53 | } 54 | 55 | public boolean isHidden() { 56 | return hidden; 57 | } 58 | 59 | @Override 60 | public String getDisplayResult() { 61 | StringBuilder result = new StringBuilder(80); 62 | maybeAppend(ssid, result); 63 | maybeAppend(networkEncryption, result); 64 | maybeAppend(password, result); 65 | maybeAppend(Boolean.toString(hidden), result); 66 | return result.toString(); 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/client/result/WifiResultParser.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.client.result; 18 | 19 | import com.google.zxing.Result; 20 | 21 | /** 22 | *Parses a WIFI configuration string. Strings will be of the form:
23 | * 24 | *{@code WIFI:T:[network type];S:[network SSID];P:[network password];H:[hidden?];;}
25 | * 26 | *The fields can appear in any order. Only "S:" is required.
27 | * 28 | * @author Vikram Aggarwal 29 | * @author Sean Owen 30 | */ 31 | public final class WifiResultParser extends ResultParser { 32 | 33 | @Override 34 | public WifiParsedResult parse(Result result) { 35 | String rawText = getMassagedText(result); 36 | if (!rawText.startsWith("WIFI:")) { 37 | return null; 38 | } 39 | String ssid = matchSinglePrefixedField("S:", rawText, ';', false); 40 | if (ssid == null || ssid.isEmpty()) { 41 | return null; 42 | } 43 | String pass = matchSinglePrefixedField("P:", rawText, ';', false); 44 | String type = matchSinglePrefixedField("T:", rawText, ';', false); 45 | if (type == null) { 46 | type = "nopass"; 47 | } 48 | boolean hidden = Boolean.parseBoolean(matchSinglePrefixedField("H:", rawText, ';', false)); 49 | return new WifiParsedResult(type, ssid, pass, hidden); 50 | } 51 | } -------------------------------------------------------------------------------- /zxinglite/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 | } -------------------------------------------------------------------------------- /zxinglite/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 | float xDiff = aX - bX; 49 | float 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 | int xDiff = aX - bX; 62 | int 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 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/common/reedsolomon/ReedSolomonEncoder.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.common.reedsolomon; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** 23 | *Implements Reed-Solomon enbcoding, as the name implies.
24 | * 25 | * @author Sean Owen 26 | * @author William Rucklidge 27 | */ 28 | public final class ReedSolomonEncoder { 29 | 30 | private final GenericGF field; 31 | private final ListThrown 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 | } -------------------------------------------------------------------------------- /zxinglite/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 | context.signalEncoderChange(newMode); 39 | break; 40 | } 41 | } 42 | int dataCount = buffer.length() - 1; 43 | int lengthFieldSize = 1; 44 | int currentSize = context.getCodewordCount() + dataCount + lengthFieldSize; 45 | context.updateSymbolInfo(currentSize); 46 | boolean mustPad = (context.getSymbolInfo().getDataCapacity() - currentSize) > 0; 47 | if (context.hasMoreCharacters() || mustPad) { 48 | if (dataCount <= 249) { 49 | buffer.setCharAt(0, (char) dataCount); 50 | } else if (dataCount <= 1555) { 51 | buffer.setCharAt(0, (char) ((dataCount / 250) + 249)); 52 | buffer.insert(1, (char) (dataCount % 250)); 53 | } else { 54 | throw new IllegalStateException( 55 | "Message length not in valid ranges: " + dataCount); 56 | } 57 | } 58 | for (int i = 0, c = buffer.length(); i < c; i++) { 59 | context.writeCodeword(randomize255State( 60 | buffer.charAt(i), context.getCodewordCount() + 1)); 61 | } 62 | } 63 | 64 | private static char randomize255State(char ch, int codewordPosition) { 65 | int pseudoRandom = ((149 * codewordPosition) % 255) + 1; 66 | int tempVariable = ch + pseudoRandom; 67 | if (tempVariable <= 255) { 68 | return (char) tempVariable; 69 | } else { 70 | return (char) (tempVariable - 256); 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /zxinglite/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 | -------------------------------------------------------------------------------- /zxinglite/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 | -------------------------------------------------------------------------------- /zxinglite/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 | -------------------------------------------------------------------------------- /zxinglite/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 >= '\0' && c <= '\u001f') { 41 | sb.append('\0'); //Shift 1 Set 42 | sb.append(c); 43 | return 2; 44 | } 45 | if (c >= '!' && c <= '/') { 46 | sb.append('\1'); //Shift 2 Set 47 | sb.append((char) (c - 33)); 48 | return 2; 49 | } 50 | if (c >= ':' && 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 == '\u0060') { 61 | sb.append('\2'); //Shift 3 Set 62 | sb.append((char) (c - 96)); 63 | return 2; 64 | } 65 | if (c >= 'A' && c <= 'Z') { 66 | sb.append('\2'); //Shift 3 Set 67 | sb.append((char) (c - 65 + 1)); 68 | return 2; 69 | } 70 | if (c >= '{' && c <= '\u007f') { 71 | sb.append('\2'); //Shift 3 Set 72 | sb.append((char) (c - 123 + 27)); 73 | return 2; 74 | } 75 | if (c >= '\u0080') { 76 | sb.append("\1\u001e"); //Shift 2, Upper Shift 77 | int len = 2; 78 | len += encodeChar((char) (c - 128), sb); 79 | return len; 80 | } 81 | HighLevelEncoder.illegalCharacter(c); 82 | return -1; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/datamatrix/encoder/X12Encoder.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 X12Encoder extends C40Encoder { 20 | 21 | @Override 22 | public int getEncodingMode() { 23 | return HighLevelEncoder.X12_ENCODATION; 24 | } 25 | 26 | @Override 27 | public void encode(EncoderContext context) { 28 | //step C 29 | StringBuilder buffer = new StringBuilder(); 30 | while (context.hasMoreCharacters()) { 31 | char c = context.getCurrentChar(); 32 | context.pos++; 33 | 34 | encodeChar(c, buffer); 35 | 36 | int count = buffer.length(); 37 | if ((count % 3) == 0) { 38 | writeNextTriplet(context, buffer); 39 | 40 | int newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, getEncodingMode()); 41 | if (newMode != getEncodingMode()) { 42 | context.signalEncoderChange(newMode); 43 | break; 44 | } 45 | } 46 | } 47 | handleEOD(context, buffer); 48 | } 49 | 50 | @Override 51 | int encodeChar(char c, StringBuilder sb) { 52 | switch (c) { 53 | case '\r': 54 | sb.append('\0'); 55 | break; 56 | case '*': 57 | sb.append('\1'); 58 | break; 59 | case '>': 60 | sb.append('\2'); 61 | break; 62 | case ' ': 63 | sb.append('\3'); 64 | break; 65 | default: 66 | if (c >= '0' && c <= '9') { 67 | sb.append((char) (c - 48 + 4)); 68 | } else if (c >= 'A' && c <= 'Z') { 69 | sb.append((char) (c - 65 + 14)); 70 | } else { 71 | HighLevelEncoder.illegalCharacter(c); 72 | } 73 | break; 74 | } 75 | return 1; 76 | } 77 | 78 | @Override 79 | void handleEOD(EncoderContext context, StringBuilder buffer) { 80 | context.updateSymbolInfo(); 81 | int available = context.getSymbolInfo().getDataCapacity() - context.getCodewordCount(); 82 | int count = buffer.length(); 83 | context.pos -= count; 84 | if (context.getRemainingCharacters() > 1 || available > 1 || 85 | context.getRemainingCharacters() != available) { 86 | context.writeCodeword(HighLevelEncoder.X12_UNLATCH); 87 | } 88 | if (context.getNewEncoding() < 0) { 89 | context.signalEncoderChange(HighLevelEncoder.ASCII_ENCODATION); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /zxinglite/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 | MapEncapsulates 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(MapImplements 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 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/oned/ITFWriter.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.WriterException; 22 | import com.google.zxing.common.BitMatrix; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * This object renders a ITF code as a {@link BitMatrix}. 28 | * 29 | * @author erik.barbara@gmail.com (Erik Barbara) 30 | */ 31 | public final class ITFWriter extends OneDimensionalCodeWriter { 32 | 33 | private static final int[] START_PATTERN = {1, 1, 1, 1}; 34 | private static final int[] END_PATTERN = {3, 1, 1}; 35 | 36 | @Override 37 | public BitMatrix encode(String contents, 38 | BarcodeFormat format, 39 | int width, 40 | int height, 41 | MapEncapsulates 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 | -------------------------------------------------------------------------------- /zxinglite/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 | -------------------------------------------------------------------------------- /zxinglite/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 | -------------------------------------------------------------------------------- /zxinglite/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 | } -------------------------------------------------------------------------------- /zxinglite/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(ListSee 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 | -------------------------------------------------------------------------------- /zxinglite/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 | -------------------------------------------------------------------------------- /zxinglite/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.
24 | * 25 | * @author Sean Owen 26 | */ 27 | public final class AlignmentPattern extends ResultPoint { 28 | 29 | private final float estimatedModuleSize; 30 | 31 | AlignmentPattern(float posX, float posY, float estimatedModuleSize) { 32 | super(posX, posY); 33 | this.estimatedModuleSize = estimatedModuleSize; 34 | } 35 | 36 | /** 37 | *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 | } -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/qrcode/detector/FinderPattern.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 a finder pattern, which are the three square patterns found in 23 | * the corners of QR Codes. It also encapsulates a count of similar finder patterns, 24 | * as a convenience to the finder's bookkeeping.
25 | * 26 | * @author Sean Owen 27 | */ 28 | public final class FinderPattern extends ResultPoint { 29 | 30 | private final float estimatedModuleSize; 31 | private final int count; 32 | 33 | FinderPattern(float posX, float posY, float estimatedModuleSize) { 34 | this(posX, posY, estimatedModuleSize, 1); 35 | } 36 | 37 | private FinderPattern(float posX, float posY, float estimatedModuleSize, int count) { 38 | super(posX, posY); 39 | this.estimatedModuleSize = estimatedModuleSize; 40 | this.count = count; 41 | } 42 | 43 | public float getEstimatedModuleSize() { 44 | return estimatedModuleSize; 45 | } 46 | 47 | int getCount() { 48 | return count; 49 | } 50 | 51 | /* 52 | void incrementCount() { 53 | this.count++; 54 | } 55 | */ 56 | 57 | /** 58 | *Determines if this finder pattern "about equals" a finder pattern at the stated 59 | * position and size -- meaning, it is at nearly the same center with nearly the same size.
60 | */ 61 | boolean aboutEquals(float moduleSize, float i, float j) { 62 | if (Math.abs(i - getY()) <= moduleSize && Math.abs(j - getX()) <= moduleSize) { 63 | float moduleSizeDiff = Math.abs(moduleSize - estimatedModuleSize); 64 | return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize; 65 | } 66 | return false; 67 | } 68 | 69 | /** 70 | * Combines this object's current estimate of a finder pattern position and module size 71 | * with a new estimate. It returns a new {@code FinderPattern} containing a weighted average 72 | * based on count. 73 | */ 74 | FinderPattern combineEstimate(float i, float j, float newModuleSize) { 75 | int combinedCount = count + 1; 76 | float combinedX = (count * getX() + j) / combinedCount; 77 | float combinedY = (count * getY() + i) / combinedCount; 78 | float combinedModuleSize = (count * estimatedModuleSize + newModuleSize) / combinedCount; 79 | return new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /zxinglite/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 | -------------------------------------------------------------------------------- /zxinglite/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 | -------------------------------------------------------------------------------- /zxinglite/src/main/java/com/google/zxing/qrcode/encoder/ByteMatrix.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 | /** 20 | * JAVAPORT: The original code was a 2D array of ints, but since it only ever gets assigned 21 | * -1, 0, and 1, I'm going to use less memory and go with bytes. 22 | * 23 | * @author dswitkin@google.com (Daniel Switkin) 24 | */ 25 | public final class ByteMatrix { 26 | 27 | private final byte[][] bytes; 28 | private final int width; 29 | private final int height; 30 | 31 | public ByteMatrix(int width, int height) { 32 | bytes = new byte[height][width]; 33 | this.width = width; 34 | this.height = height; 35 | } 36 | 37 | public int getHeight() { 38 | return height; 39 | } 40 | 41 | public int getWidth() { 42 | return width; 43 | } 44 | 45 | public byte get(int x, int y) { 46 | return bytes[y][x]; 47 | } 48 | 49 | /** 50 | * @return an internal representation as bytes, in row-major order. array[y][x] represents point (x,y) 51 | */ 52 | public byte[][] getArray() { 53 | return bytes; 54 | } 55 | 56 | public void set(int x, int y, byte value) { 57 | bytes[y][x] = value; 58 | } 59 | 60 | public void set(int x, int y, int value) { 61 | bytes[y][x] = (byte) value; 62 | } 63 | 64 | public void set(int x, int y, boolean value) { 65 | bytes[y][x] = (byte) (value ? 1 : 0); 66 | } 67 | 68 | public void clear(byte value) { 69 | for (int y = 0; y < height; ++y) { 70 | for (int x = 0; x < width; ++x) { 71 | bytes[y][x] = value; 72 | } 73 | } 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | StringBuilder result = new StringBuilder(2 * width * height + 2); 79 | for (int y = 0; y < height; ++y) { 80 | for (int x = 0; x < width; ++x) { 81 | switch (bytes[y][x]) { 82 | case 0: 83 | result.append(" 0"); 84 | break; 85 | case 1: 86 | result.append(" 1"); 87 | break; 88 | default: 89 | result.append(" "); 90 | break; 91 | } 92 | } 93 | result.append('\n'); 94 | } 95 | return result.toString(); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /zxinglite/src/main/res/drawable/scanline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangxixi88/ZxingLite/21e4399486a9c03589285af648051393c6ef9b36/zxinglite/src/main/res/drawable/scanline.png -------------------------------------------------------------------------------- /zxinglite/src/main/res/raw/beep.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangxixi88/ZxingLite/21e4399486a9c03589285af648051393c6ef9b36/zxinglite/src/main/res/raw/beep.ogg -------------------------------------------------------------------------------- /zxinglite/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 |