X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=android%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fandroid%2FDecodeThread.java;h=75e5bad74da92cb40fa39040d984689c7bdaa28f;hb=b320f70e522f4f2c126cf2e3ff5d8db7b64fb62c;hp=c3d77de9f34500377bddb2c5ec4d45a042b20fb8;hpb=3a13e0d4991992e7a310123a8ff2a2d3293ad39d;p=zxing.git diff --git a/android/src/com/google/zxing/client/android/DecodeThread.java b/android/src/com/google/zxing/client/android/DecodeThread.java index c3d77de9..75e5bad7 100755 --- a/android/src/com/google/zxing/client/android/DecodeThread.java +++ b/android/src/com/google/zxing/client/android/DecodeThread.java @@ -27,6 +27,7 @@ import android.preference.PreferenceManager; import java.util.Hashtable; import java.util.Vector; +import java.util.concurrent.CountDownLatch; /** * This thread does all the heavy lifting of decoding the images. @@ -37,13 +38,20 @@ final class DecodeThread extends Thread { public static final String BARCODE_BITMAP = "barcode_bitmap"; - private final Handler handler; + private final CaptureActivity activity; + private final Hashtable hints; + private Handler handler; + private final CountDownLatch handlerInitLatch; DecodeThread(CaptureActivity activity, Vector decodeFormats, String characterSet, ResultPointCallback resultPointCallback) { - Hashtable hints = new Hashtable(3); + + this.activity = activity; + handlerInitLatch = new CountDownLatch(1); + + hints = new Hashtable(3); // The prefs can't change while the thread is running, so pick them up once here. if (decodeFormats == null || decodeFormats.isEmpty()) { @@ -66,17 +74,22 @@ final class DecodeThread extends Thread { } hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback); - - this.handler = new DecodeHandler(activity, hints); } Handler getHandler() { + try { + handlerInitLatch.await(); + } catch (InterruptedException ie) { + // continue? + } return handler; } @Override public void run() { Looper.prepare(); + handler = new DecodeHandler(activity, hints); + handlerInitLatch.countDown(); Looper.loop(); }