
com.google.zxing.client.android.decode.DecodeThread Maven / Gradle / Ivy
/*
* Copyright (c) 2015 [[email protected] | [email protected]]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.android.decode;
import android.app.Activity;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.snicesoft.android.scan.IScan;
import java.util.concurrent.CountDownLatch;
/**
* This thread does all the heavy lifting of decoding the images.
*
* @author [email protected] (Daniel Switkin)
*/
public class DecodeThread extends Thread {
public static final String BARCODE_BITMAP = "BARCODE_BITMAP";
public static final String DECODE_MODE = "DECODE_MODE";
public static final String DECODE_TIME = "DECODE_TIME";
private final Activity activity;
private Handler handler;
private final CountDownLatch handlerInitLatch;
public DecodeThread(Activity activity) {
this.activity = activity;
if (!(activity instanceof IScan)) {
Log.e("DecodeThread", "Activity must implements IScan.");
}
handlerInitLatch = new CountDownLatch(1);
}
public Handler getHandler() {
try {
handlerInitLatch.await();
} catch (InterruptedException ie) {
// continue?
}
return handler;
}
@Override
public void run() {
Looper.prepare();
handler = new DecodeHandler((IScan) activity);
handlerInitLatch.countDown();
Looper.loop();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy