From 8300f78e358e4c1662cd9ea36e666e065ac550bf Mon Sep 17 00:00:00 2001 From: hupei Date: Mon, 11 Jul 2016 11:18:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scanner/sample/BasicScannerActivity.java | 14 +- .../zxing/scanner/sample/MainActivity.java | 3 +- .../sample/result/AddressBookActivity.java | 8 +- .../scanner/sample/result/TextActivity.java | 4 +- .../scanner/sample/result/UriActivity.java | 4 +- .../com/mylhyl/zxing/scanner/BeepManager.java | 5 - .../zxing/scanner/ScannerViewHandler.java | 8 +- .../mylhyl/zxing/scanner/ViewfinderView.java | 4 - .../mylhyl/zxing/scanner/common/Intents.java | 404 +++++++----------- .../mylhyl/zxing/scanner/common/Scanner.java | 10 - 10 files changed, 173 insertions(+), 291 deletions(-) diff --git a/sample/src/main/java/com/mylhyl/zxing/scanner/sample/BasicScannerActivity.java b/sample/src/main/java/com/mylhyl/zxing/scanner/sample/BasicScannerActivity.java index 5b1c7a2..71f6c19 100644 --- a/sample/src/main/java/com/mylhyl/zxing/scanner/sample/BasicScannerActivity.java +++ b/sample/src/main/java/com/mylhyl/zxing/scanner/sample/BasicScannerActivity.java @@ -15,6 +15,7 @@ import com.google.zxing.client.result.ParsedResultType; import com.google.zxing.client.result.URIParsedResult; import com.mylhyl.zxing.scanner.OnScannerCompletionListener; +import com.mylhyl.zxing.scanner.common.Intents; import com.mylhyl.zxing.scanner.common.Scanner; /** @@ -23,7 +24,6 @@ public abstract class BasicScannerActivity extends AppCompatActivity implements OnScannerCompletionListener { public static final int REQUEST_CODE_SCANNER = 188; public static final String EXTRA_RETURN_SCANNER_RESULT = "return_scanner_result"; - public static final String EXTRA_RETURN_SCANNER_RESULT_TEXT = "return_scanner_result_text"; private boolean mReturnScanResult; @@ -61,18 +61,18 @@ public void OnScannerCompletion(Result rawResult, ParsedResult parsedResult, Bit switch (type) { case ADDRESSBOOK: AddressBookParsedResult addressResult = (AddressBookParsedResult) parsedResult; - bundle.putStringArray(Scanner.result.EXTRA_RESULT_ADDRESS_BOOK_NAME, addressResult.getNames()); - bundle.putStringArray(Scanner.result.EXTRA_RESULT_ADDRESS_BOOK_PHONE_NUMBER, addressResult.getPhoneNumbers()); - bundle.putStringArray(Scanner.result.EXTRA_RESULT_ADDRESS_BOOK_EMAIL, addressResult.getEmails()); + bundle.putStringArray(Intents.AddressBookConnect.NAME, addressResult.getNames()); + bundle.putStringArray(Intents.AddressBookConnect.NUMBER, addressResult.getPhoneNumbers()); + bundle.putStringArray(Intents.AddressBookConnect.EMAIL, addressResult.getEmails()); break; case PRODUCT: break; case URI: URIParsedResult uriParsedResult = (URIParsedResult) parsedResult; - bundle.putString(Scanner.result.EXTRA_RESULT_URI, uriParsedResult.getURI()); + bundle.putString(Intents.URIContents.URI, uriParsedResult.getURI()); break; case TEXT: - bundle.putString(Scanner.result.EXTRA_RESULT_TEXT, rawResult.getText()); + bundle.putString(Intents.Scan.RESULT, rawResult.getText()); break; case GEO: break; @@ -86,7 +86,7 @@ public void OnScannerCompletion(Result rawResult, ParsedResult parsedResult, Bit private void onReturnScanResult(Result rawResult) { Intent intent = getIntent(); - intent.putExtra(EXTRA_RETURN_SCANNER_RESULT_TEXT, rawResult.getText()); + intent.putExtra(Intents.Scan.RESULT, rawResult.getText()); setResult(Activity.RESULT_OK, intent); finish(); } diff --git a/sample/src/main/java/com/mylhyl/zxing/scanner/sample/MainActivity.java b/sample/src/main/java/com/mylhyl/zxing/scanner/sample/MainActivity.java index c65e4ca..7869989 100644 --- a/sample/src/main/java/com/mylhyl/zxing/scanner/sample/MainActivity.java +++ b/sample/src/main/java/com/mylhyl/zxing/scanner/sample/MainActivity.java @@ -19,6 +19,7 @@ import com.google.zxing.client.result.ParsedResultType; import com.mylhyl.zxing.scanner.common.Contents; +import com.mylhyl.zxing.scanner.common.Intents; import com.mylhyl.zxing.scanner.encode.QREncode; import java.io.ByteArrayOutputStream; @@ -114,7 +115,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != Activity.RESULT_CANCELED && resultCode == Activity.RESULT_OK) { if (requestCode == EnCodeActivity.REQUEST_CODE_SCANNER) { if (data != null) { - String stringExtra = data.getStringExtra(EnCodeActivity.EXTRA_RETURN_SCANNER_RESULT_TEXT); + String stringExtra = data.getStringExtra(Intents.Scan.RESULT); tvResult.setText(stringExtra); } } else if (requestCode == PICK_CONTACT) { diff --git a/sample/src/main/java/com/mylhyl/zxing/scanner/sample/result/AddressBookActivity.java b/sample/src/main/java/com/mylhyl/zxing/scanner/sample/result/AddressBookActivity.java index ed150cc..8b16553 100644 --- a/sample/src/main/java/com/mylhyl/zxing/scanner/sample/result/AddressBookActivity.java +++ b/sample/src/main/java/com/mylhyl/zxing/scanner/sample/result/AddressBookActivity.java @@ -5,7 +5,7 @@ import android.os.Bundle; import android.widget.TextView; -import com.mylhyl.zxing.scanner.common.Scanner; +import com.mylhyl.zxing.scanner.common.Intents; import com.mylhyl.zxing.scanner.sample.BasicActivity; import com.mylhyl.zxing.scanner.sample.R; @@ -23,9 +23,9 @@ protected void onCreate(Bundle savedInstanceState) { Bundle extras = getIntent().getExtras(); - String[] names = extras.getStringArray(Scanner.result.EXTRA_RESULT_ADDRESS_BOOK_NAME); - String[] phoneNumbers = extras.getStringArray(Scanner.result.EXTRA_RESULT_ADDRESS_BOOK_PHONE_NUMBER); - String[] emails = extras.getStringArray(Scanner.result.EXTRA_RESULT_ADDRESS_BOOK_EMAIL); + String[] names = extras.getStringArray(Intents.AddressBookConnect.NAME); + String[] phoneNumbers = extras.getStringArray(Intents.AddressBookConnect.NUMBER); + String[] emails = extras.getStringArray(Intents.AddressBookConnect.EMAIL); StringBuffer sb = new StringBuffer(); diff --git a/sample/src/main/java/com/mylhyl/zxing/scanner/sample/result/TextActivity.java b/sample/src/main/java/com/mylhyl/zxing/scanner/sample/result/TextActivity.java index 9be22da..bf04210 100644 --- a/sample/src/main/java/com/mylhyl/zxing/scanner/sample/result/TextActivity.java +++ b/sample/src/main/java/com/mylhyl/zxing/scanner/sample/result/TextActivity.java @@ -5,7 +5,7 @@ import android.os.Bundle; import android.widget.TextView; -import com.mylhyl.zxing.scanner.common.Scanner; +import com.mylhyl.zxing.scanner.common.Intents; import com.mylhyl.zxing.scanner.sample.BasicActivity; import com.mylhyl.zxing.scanner.sample.R; @@ -20,7 +20,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_text); Bundle extras = getIntent().getExtras(); if (extras != null) - ((TextView) findViewById(R.id.textView3)).setText(extras.getString(Scanner.result.EXTRA_RESULT_TEXT)); + ((TextView) findViewById(R.id.textView3)).setText(extras.getString(Intents.Scan.RESULT)); } public static void gotoActivity(Activity activity, Bundle bundle) { diff --git a/sample/src/main/java/com/mylhyl/zxing/scanner/sample/result/UriActivity.java b/sample/src/main/java/com/mylhyl/zxing/scanner/sample/result/UriActivity.java index 517c295..6213873 100644 --- a/sample/src/main/java/com/mylhyl/zxing/scanner/sample/result/UriActivity.java +++ b/sample/src/main/java/com/mylhyl/zxing/scanner/sample/result/UriActivity.java @@ -7,7 +7,7 @@ import android.webkit.WebViewClient; import com.mylhyl.crlayout.SwipeRefreshWebView; -import com.mylhyl.zxing.scanner.common.Scanner; +import com.mylhyl.zxing.scanner.common.Intents; import com.mylhyl.zxing.scanner.sample.BasicActivity; import com.mylhyl.zxing.scanner.sample.R; @@ -21,7 +21,7 @@ public class UriActivity extends BasicActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_uri); - String uri = getIntent().getStringExtra(Scanner.result.EXTRA_RESULT_URI); + String uri = getIntent().getStringExtra(Intents.URIContents.URI); swipeRefreshWebView = (SwipeRefreshWebView) findViewById(R.id.webView); swipeRefreshWebView.getScrollView().loadUrl(uri); swipeRefreshWebView.getScrollView().setWebViewClient(new SampleWebViewClient()); diff --git a/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/BeepManager.java b/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/BeepManager.java index 92ed08b..a7e3760 100644 --- a/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/BeepManager.java +++ b/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/BeepManager.java @@ -21,7 +21,6 @@ import android.media.AudioManager; import android.media.MediaPlayer; import android.os.Vibrator; -import android.util.Log; import java.io.Closeable; import java.io.IOException; @@ -31,8 +30,6 @@ */ final class BeepManager implements MediaPlayer.OnErrorListener, Closeable { -// private static final String TAG = BeepManager.class.getSimpleName(); - private static final float BEEP_VOLUME = 0.10f; private static final long VIBRATE_DURATION = 200L; @@ -110,7 +107,6 @@ private MediaPlayer buildMediaPlayer(Context activity) { mediaPlayer.prepare(); return mediaPlayer; } catch (IOException ioe) { -// Log.w(TAG, ioe); mediaPlayer.release(); return null; } @@ -121,7 +117,6 @@ public synchronized boolean onError(MediaPlayer mp, int what, int extra) { if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) { //播放错误 } else { - // possibly media player error, so release and recreate close(); updatePrefs(); } diff --git a/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/ScannerViewHandler.java b/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/ScannerViewHandler.java index 49b1465..4a6c016 100644 --- a/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/ScannerViewHandler.java +++ b/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/ScannerViewHandler.java @@ -85,7 +85,6 @@ public void handleMessage(Message message) { if (compressedBitmap != null) { barcode = BitmapFactory.decodeByteArray(compressedBitmap, 0, compressedBitmap.length, null); - // Mutable copy: barcode = barcode.copy(Bitmap.Config.ARGB_8888, true); } scaleFactor = bundle @@ -95,8 +94,6 @@ public void handleMessage(Message message) { .handleDecode((Result) message.obj, barcode, scaleFactor); break; case Scanner.DECODE_FAILED: - // We're decoding as fast as possible, so when one decode fails, - // start another. state = State.PREVIEW; cameraManager.requestPreviewFrame(decodeThread.getHandler(), Scanner.DECODE); @@ -114,14 +111,11 @@ public void quitSynchronously() { Message quit = Message.obtain(decodeThread.getHandler(), Scanner.QUIT); quit.sendToTarget(); try { - // Wait at most half a second; should be enough time, and onPause() - // will timeout quickly decodeThread.join(500L); } catch (InterruptedException e) { - // continue + e.printStackTrace(); } - // Be absolutely sure we don't send any queued up messages removeMessages(Scanner.DECODE_SUCCEEDED); removeMessages(Scanner.DECODE_FAILED); } diff --git a/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/ViewfinderView.java b/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/ViewfinderView.java index d08a5ff..755fcfc 100644 --- a/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/ViewfinderView.java +++ b/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/ViewfinderView.java @@ -73,12 +73,9 @@ final class ViewfinderView extends View { private boolean drawTextGravityBottom = true;//提示文字位置 private int drawTextMargin;//提示文字与扫描框距离 private boolean isLaserGridLine;//是否为网格资源文件 - private boolean isDraw;//是否绘制过(扫描框、扫描框4角、扫描提示文字) - // This constructor is used when the class is built from an XML resource. public ViewfinderView(Context context, AttributeSet attrs) { super(context, attrs); - // Initialize these once for performance rather than calling them every time in onDraw(). paint = new Paint(Paint.ANTI_ALIAS_FLAG); possibleResultPoints = new ArrayList<>(5); lastPossibleResultPoints = null; @@ -293,7 +290,6 @@ public void drawViewfinder() { if (resultBitmap != null) { resultBitmap.recycle(); } - isDraw = false; invalidate(); } diff --git a/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/common/Intents.java b/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/common/Intents.java index a89ce77..87442ea 100644 --- a/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/common/Intents.java +++ b/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/common/Intents.java @@ -23,263 +23,169 @@ * @author dswitkin@google.com (Daniel Switkin) */ public final class Intents { - private Intents() { - } - - /** - * Constants related to the {@link Scan#ACTION} Intent. - */ - public static final class Scan { - /** - * Send this intent to open the Barcodes app in scanning mode, find a barcode, and return - * the results. - */ - public static final String ACTION = "com.google.zxing.client.android.SCAN"; - - /** - * By default, sending this will decode all barcodes that we understand. However it - * may be useful to limit scanning to certain formats. Use - * {@link android.content.Intent#putExtra(String, String)} with one of the values below. - * - * Setting this is effectively shorthand for setting explicit formats with {@link #FORMATS}. - * It is overridden by that setting. - */ - public static final String MODE = "SCAN_MODE"; - - /** - * Decode only UPC and EAN barcodes. This is the right choice for shopping apps which get - * prices, reviews, etc. for products. - */ - public static final String PRODUCT_MODE = "PRODUCT_MODE"; - - /** - * Decode only 1D barcodes. - */ - public static final String ONE_D_MODE = "ONE_D_MODE"; - - /** - * Decode only QR codes. - */ - public static final String QR_CODE_MODE = "QR_CODE_MODE"; - - /** - * Decode only Data Matrix codes. - */ - public static final String DATA_MATRIX_MODE = "DATA_MATRIX_MODE"; - - /** - * Decode only Aztec. - */ - public static final String AZTEC_MODE = "AZTEC_MODE"; - - /** - * Decode only PDF417. - */ - public static final String PDF417_MODE = "PDF417_MODE"; - - /** - * Comma-separated list of formats to scan for. The values must match the names of - * {@link com.google.zxing.BarcodeFormat}s, e.g. {@link com.google.zxing.BarcodeFormat#EAN_13}. - * Example: "EAN_13,EAN_8,QR_CODE". This overrides {@link #MODE}. - */ - public static final String FORMATS = "SCAN_FORMATS"; - - /** - * Optional parameter to specify the id of the camera from which to recognize barcodes. - * Overrides the default camera that would otherwise would have been selected. - * If provided, should be an int. - */ - public static final String CAMERA_ID = "SCAN_CAMERA_ID"; - - /** - * @see com.google.zxing.DecodeHintType#CHARACTER_SET - */ - public static final String CHARACTER_SET = "CHARACTER_SET"; - - /** - * Optional parameters to specify the width and height of the scanning rectangle in pixels. - * The app will try to honor these, but will clamp them to the size of the preview frame. - * You should specify both or neither, and pass the size as an int. - */ - public static final String WIDTH = "SCAN_WIDTH"; - public static final String HEIGHT = "SCAN_HEIGHT"; - - /** - * Desired duration in milliseconds for which to pause after a successful scan before - * returning to the calling intent. Specified as a long, not an integer! - * For example: 1000L, not 1000. - */ - public static final String RESULT_DISPLAY_DURATION_MS = "RESULT_DISPLAY_DURATION_MS"; - - /** - * Prompt to show on-screen when scanning by intent. Specified as a {@link String}. - */ - public static final String PROMPT_MESSAGE = "PROMPT_MESSAGE"; - - /** - * If a barcode is found, Barcodes returns {@link android.app.Activity#RESULT_OK} to - * {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)} - * of the app which requested the scan via - * {@link android.app.Activity#startActivityForResult(android.content.Intent, int)} - * The barcodes contents can be retrieved with - * {@link android.content.Intent#getStringExtra(String)}. - * If the user presses Back, the result code will be {@link android.app.Activity#RESULT_CANCELED}. - */ - public static final String RESULT = "SCAN_RESULT"; - - /** - * Call {@link android.content.Intent#getStringExtra(String)} with {@link #RESULT_FORMAT} - * to determine which barcode format was found. - * See {@link com.google.zxing.BarcodeFormat} for possible values. - */ - public static final String RESULT_FORMAT = "SCAN_RESULT_FORMAT"; - - /** - * Call {@link android.content.Intent#getStringExtra(String)} with {@link #RESULT_UPC_EAN_EXTENSION} - * to return the content of any UPC extension barcode that was also found. Only applicable - * to {@link com.google.zxing.BarcodeFormat#UPC_A} and {@link com.google.zxing.BarcodeFormat#EAN_13} - * formats. - */ - public static final String RESULT_UPC_EAN_EXTENSION = "SCAN_RESULT_UPC_EAN_EXTENSION"; - - /** - * Call {@link android.content.Intent#getByteArrayExtra(String)} with {@link #RESULT_BYTES} - * to get a {@code byte[]} of raw bytes in the barcode, if available. - */ - public static final String RESULT_BYTES = "SCAN_RESULT_BYTES"; - - /** - * Key for the value of {@link com.google.zxing.ResultMetadataType#ORIENTATION}, if available. - * Call {@link android.content.Intent#getIntArrayExtra(String)} with {@link #RESULT_ORIENTATION}. - */ - public static final String RESULT_ORIENTATION = "SCAN_RESULT_ORIENTATION"; - - /** - * Key for the value of {@link com.google.zxing.ResultMetadataType#ERROR_CORRECTION_LEVEL}, if available. - * Call {@link android.content.Intent#getStringExtra(String)} with {@link #RESULT_ERROR_CORRECTION_LEVEL}. - */ - public static final String RESULT_ERROR_CORRECTION_LEVEL = "SCAN_RESULT_ERROR_CORRECTION_LEVEL"; - - /** - * Prefix for keys that map to the values of {@link com.google.zxing.ResultMetadataType#BYTE_SEGMENTS}, - * if available. The actual values will be set under a series of keys formed by adding 0, 1, 2, ... - * to this prefix. So the first byte segment is under key "SCAN_RESULT_BYTE_SEGMENTS_0" for example. - * Call {@link android.content.Intent#getByteArrayExtra(String)} with these keys. - */ - public static final String RESULT_BYTE_SEGMENTS_PREFIX = "SCAN_RESULT_BYTE_SEGMENTS_"; - - /** - * Setting this to false will not save scanned codes in the history. Specified as a {@code boolean}. - */ - public static final String SAVE_HISTORY = "SAVE_HISTORY"; - - private Scan() { - } - } - - /** - * Constants related to the {@link Encode#ACTION} Intent. - */ - public static final class Encode { - /** - * Send this intent to encode a piece of data as a QR code and display it full screen, so - * that another person can scan the barcode from your screen. - */ - public static final String ACTION = "com.google.zxing.client.android.ENCODE"; - - /** - * The data to encode. Use {@link android.content.Intent#putExtra(String, String)} or - * {@link android.content.Intent#putExtra(String, android.os.Bundle)}, - * depending on the type and format specified. Non-QR Code formats should - * just use a String here. For QR Code, see Contents for details. - */ - public static final String DATA = "ENCODE_DATA"; - - /** - * The type of data being supplied if the format is QR Code. Use - * {@link android.content.Intent#putExtra(String, String)} with one of {@link Contents.Type}. - */ - public static final String TYPE = "ENCODE_TYPE"; - - /** - * The barcode format to be displayed. If this isn't specified or is blank, - * it defaults to QR Code. Use {@link android.content.Intent#putExtra(String, String)}, where - * format is one of {@link com.google.zxing.BarcodeFormat}. - */ - public static final String FORMAT = "ENCODE_FORMAT"; - - /** - * Normally the contents of the barcode are displayed to the user in a TextView. Setting this - * boolean to false will hide that TextView, showing only the encode barcode. - */ - public static final String SHOW_CONTENTS = "ENCODE_SHOW_CONTENTS"; - - private Encode() { + private Intents() { } - } - /** - * Constants related to the {@link SearchBookContents#ACTION} Intent. - */ - public static final class SearchBookContents { /** - * Use Google Book Search to search the contents of the book provided. - */ - public static final String ACTION = "com.google.zxing.client.android.SEARCH_BOOK_CONTENTS"; - - /** - * The book to search, identified by ISBN number. - */ - public static final String ISBN = "ISBN"; - - /** - * An optional field which is the text to search for. - */ - public static final String QUERY = "QUERY"; - - private SearchBookContents() { + * Constants related to the {@link Scan#ACTION} Intent. + */ + public static final class Scan { + /** + * Send this intent to open the Barcodes app in scanning mode, find a barcode, and return + * the results. + */ + public static final String ACTION = "com.google.zxing.client.android.SCAN"; + + /** + * By default, sending this will decode all barcodes that we understand. However it + * may be useful to limit scanning to certain formats. Use + * {@link android.content.Intent#putExtra(String, String)} with one of the values below. + *

+ * Setting this is effectively shorthand for setting explicit formats with {@link #FORMATS}. + * It is overridden by that setting. + */ + public static final String MODE = "SCAN_MODE"; + + /** + * Decode only UPC and EAN barcodes. This is the right choice for shopping apps which get + * prices, reviews, etc. for products. + */ + public static final String PRODUCT_MODE = "PRODUCT_MODE"; + + /** + * Decode only 1D barcodes. + */ + public static final String ONE_D_MODE = "ONE_D_MODE"; + + /** + * Decode only QR codes. + */ + public static final String QR_CODE_MODE = "QR_CODE_MODE"; + + /** + * Decode only Data Matrix codes. + */ + public static final String DATA_MATRIX_MODE = "DATA_MATRIX_MODE"; + + /** + * Decode only Aztec. + */ + public static final String AZTEC_MODE = "AZTEC_MODE"; + + /** + * Decode only PDF417. + */ + public static final String PDF417_MODE = "PDF417_MODE"; + + /** + * Comma-separated list of formats to scan for. The values must match the names of + * {@link com.google.zxing.BarcodeFormat}s, e.g. {@link com.google.zxing.BarcodeFormat#EAN_13}. + * Example: "EAN_13,EAN_8,QR_CODE". This overrides {@link #MODE}. + */ + public static final String FORMATS = "SCAN_FORMATS"; + + /** + * Optional parameter to specify the id of the camera from which to recognize barcodes. + * Overrides the default camera that would otherwise would have been selected. + * If provided, should be an int. + */ + public static final String CAMERA_ID = "SCAN_CAMERA_ID"; + + /** + * @see com.google.zxing.DecodeHintType#CHARACTER_SET + */ + public static final String CHARACTER_SET = "CHARACTER_SET"; + + /** + * Optional parameters to specify the width and height of the scanning rectangle in pixels. + * The app will try to honor these, but will clamp them to the size of the preview frame. + * You should specify both or neither, and pass the size as an int. + */ + public static final String WIDTH = "SCAN_WIDTH"; + public static final String HEIGHT = "SCAN_HEIGHT"; + + /** + * Desired duration in milliseconds for which to pause after a successful scan before + * returning to the calling intent. Specified as a long, not an integer! + * For example: 1000L, not 1000. + */ + public static final String RESULT_DISPLAY_DURATION_MS = "RESULT_DISPLAY_DURATION_MS"; + + /** + * Prompt to show on-screen when scanning by intent. Specified as a {@link String}. + */ + public static final String PROMPT_MESSAGE = "PROMPT_MESSAGE"; + + /** + * If a barcode is found, Barcodes returns {@link android.app.Activity#RESULT_OK} to + * {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)} + * of the app which requested the scan via + * {@link android.app.Activity#startActivityForResult(android.content.Intent, int)} + * The barcodes contents can be retrieved with + * {@link android.content.Intent#getStringExtra(String)}. + * If the user presses Back, the result code will be {@link android.app.Activity#RESULT_CANCELED}. + */ + public static final String RESULT = "SCAN_RESULT"; + + /** + * Call {@link android.content.Intent#getStringExtra(String)} with {@link #RESULT_FORMAT} + * to determine which barcode format was found. + * See {@link com.google.zxing.BarcodeFormat} for possible values. + */ + public static final String RESULT_FORMAT = "SCAN_RESULT_FORMAT"; + + /** + * Call {@link android.content.Intent#getStringExtra(String)} with {@link #RESULT_UPC_EAN_EXTENSION} + * to return the content of any UPC extension barcode that was also found. Only applicable + * to {@link com.google.zxing.BarcodeFormat#UPC_A} and {@link com.google.zxing.BarcodeFormat#EAN_13} + * formats. + */ + public static final String RESULT_UPC_EAN_EXTENSION = "SCAN_RESULT_UPC_EAN_EXTENSION"; + + /** + * Call {@link android.content.Intent#getByteArrayExtra(String)} with {@link #RESULT_BYTES} + * to get a {@code byte[]} of raw bytes in the barcode, if available. + */ + public static final String RESULT_BYTES = "SCAN_RESULT_BYTES"; + + /** + * Key for the value of {@link com.google.zxing.ResultMetadataType#ORIENTATION}, if available. + * Call {@link android.content.Intent#getIntArrayExtra(String)} with {@link #RESULT_ORIENTATION}. + */ + public static final String RESULT_ORIENTATION = "SCAN_RESULT_ORIENTATION"; + + /** + * Key for the value of {@link com.google.zxing.ResultMetadataType#ERROR_CORRECTION_LEVEL}, if available. + * Call {@link android.content.Intent#getStringExtra(String)} with {@link #RESULT_ERROR_CORRECTION_LEVEL}. + */ + public static final String RESULT_ERROR_CORRECTION_LEVEL = "SCAN_RESULT_ERROR_CORRECTION_LEVEL"; + + /** + * Prefix for keys that map to the values of {@link com.google.zxing.ResultMetadataType#BYTE_SEGMENTS}, + * if available. The actual values will be set under a series of keys formed by adding 0, 1, 2, ... + * to this prefix. So the first byte segment is under key "SCAN_RESULT_BYTE_SEGMENTS_0" for example. + * Call {@link android.content.Intent#getByteArrayExtra(String)} with these keys. + */ + public static final String RESULT_BYTE_SEGMENTS_PREFIX = "SCAN_RESULT_BYTE_SEGMENTS_"; + + private Scan() { + } } - } - /** - * Constants related to the {@link WifiConnect#ACTION} Intent. - */ - public static final class WifiConnect { - /** - * Internal intent used to trigger connection to a wi-fi network. - */ - public static final String ACTION = "com.google.zxing.client.android.WIFI_CONNECT"; + public static final class URIContents { + public static final String URI = "uri_uri"; + public static final String TITLE = "uri_title"; - /** - * The network to connect to, all the configuration provided here. - */ - public static final String SSID = "SSID"; - - /** - * The network to connect to, all the configuration provided here. - */ - public static final String TYPE = "TYPE"; - - /** - * The network to connect to, all the configuration provided here. - */ - public static final String PASSWORD = "PASSWORD"; - - private WifiConnect() { + private URIContents() { + } } - } - /** - * Constants related to the {@link Share#ACTION} Intent. - */ - public static final class Share { - /** - * Give the user a choice of items to encode as a barcode, then render it as a QR Code and - * display onscreen for a friend to scan with their phone. - */ - public static final String ACTION = "com.google.zxing.client.android.SHARE"; + public static final class AddressBookConnect { + public static final String NAME = "address_book_name"; + public static final String NUMBER = "address_book_phone_number"; + public static final String EMAIL = "address_book_email"; - private Share() { + private AddressBookConnect() { + } } - } } diff --git a/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/common/Scanner.java b/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/common/Scanner.java index 79ba0c8..ff55f13 100644 --- a/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/common/Scanner.java +++ b/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/common/Scanner.java @@ -27,16 +27,6 @@ public static class color { public static final int RESULT_POINTS = 0xc099cc00; } - public static class result { - //联系人 - public static final String EXTRA_RESULT_ADDRESS_BOOK_NAME = "result_address_book_name"; - public static final String EXTRA_RESULT_ADDRESS_BOOK_PHONE_NUMBER = "result_address_book_phone_number"; - public static final String EXTRA_RESULT_ADDRESS_BOOK_EMAIL = "result_address_book_email"; - - public static final String EXTRA_RESULT_URI = "result_uri"; - public static final String EXTRA_RESULT_TEXT = "result_text"; - } - public static ParsedResult parseResult(Result rawResult) { if (rawResult == null) return null; return ResultParser.parseResult(rawResult);