DecodeThread.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (C) 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. package com.rdgk.cemetery.zxing.decoding;
  17. import android.os.Handler;
  18. import android.os.Looper;
  19. import com.google.zxing.BarcodeFormat;
  20. import com.google.zxing.DecodeHintType;
  21. import com.google.zxing.ResultPointCallback;
  22. import com.rdgk.cemetery.zxing.activity.CaptureActivity;
  23. import java.util.Hashtable;
  24. import java.util.Vector;
  25. import java.util.concurrent.CountDownLatch;
  26. /**
  27. * This thread does all the heavy lifting of decoding the images.
  28. * �����߳�
  29. */
  30. final class DecodeThread extends Thread {
  31. public static final String BARCODE_BITMAP = "barcode_bitmap";
  32. private final CaptureActivity activity;
  33. private final Hashtable<DecodeHintType, Object> hints;
  34. private Handler handler;
  35. private final CountDownLatch handlerInitLatch;
  36. DecodeThread(CaptureActivity activity,
  37. Vector<BarcodeFormat> decodeFormats,
  38. String characterSet,
  39. ResultPointCallback resultPointCallback) {
  40. this.activity = activity;
  41. handlerInitLatch = new CountDownLatch(1);
  42. hints = new Hashtable<DecodeHintType, Object>(3);
  43. if (decodeFormats == null || decodeFormats.isEmpty()) {
  44. decodeFormats = new Vector<BarcodeFormat>();
  45. decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
  46. decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
  47. decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
  48. }
  49. hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
  50. if (characterSet != null) {
  51. hints.put(DecodeHintType.CHARACTER_SET, characterSet);
  52. }
  53. hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
  54. }
  55. Handler getHandler() {
  56. try {
  57. handlerInitLatch.await();
  58. } catch (InterruptedException ie) {
  59. // continue?
  60. }
  61. return handler;
  62. }
  63. @Override
  64. public void run() {
  65. Looper.prepare();
  66. handler = new DecodeHandler(activity, hints);
  67. handlerInitLatch.countDown();
  68. Looper.loop();
  69. }
  70. }