mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
Remove last usages of Runnable/Timer in favor of AsyncTask
git-svn-id: https://zxing.googlecode.com/svn/trunk@2378 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
24f5b64a2f
commit
3a33c03f8d
|
@ -24,8 +24,7 @@ import android.content.DialogInterface;
|
|||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class FinishListener
|
||||
implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener, Runnable {
|
||||
public final class FinishListener implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
|
||||
|
||||
private final Activity activityToFinish;
|
||||
|
||||
|
@ -43,8 +42,7 @@ public final class FinishListener
|
|||
run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
private void run() {
|
||||
activityToFinish.finish();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,14 +19,13 @@ package com.google.zxing.client.android.camera;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.hardware.Camera;
|
||||
import android.os.AsyncTask;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import com.google.zxing.client.android.PreferencesActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
final class AutoFocusManager implements Camera.AutoFocusCallback {
|
||||
|
||||
|
@ -43,12 +42,10 @@ final class AutoFocusManager implements Camera.AutoFocusCallback {
|
|||
private boolean active;
|
||||
private final boolean useAutoFocus;
|
||||
private final Camera camera;
|
||||
private final Timer timer;
|
||||
private TimerTask outstandingTask;
|
||||
private AutoFocusTask outstandingTask;
|
||||
|
||||
AutoFocusManager(Context context, Camera camera) {
|
||||
this.camera = camera;
|
||||
timer = new Timer(true);
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String currentFocusMode = camera.getParameters().getFocusMode();
|
||||
useAutoFocus =
|
||||
|
@ -61,15 +58,7 @@ final class AutoFocusManager implements Camera.AutoFocusCallback {
|
|||
@Override
|
||||
public synchronized void onAutoFocus(boolean success, Camera theCamera) {
|
||||
if (active) {
|
||||
outstandingTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (active) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
};
|
||||
timer.schedule(outstandingTask, AUTO_FOCUS_INTERVAL_MS);
|
||||
outstandingTask = new AutoFocusTask();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,10 +84,27 @@ final class AutoFocusManager implements Camera.AutoFocusCallback {
|
|||
}
|
||||
}
|
||||
if (outstandingTask != null) {
|
||||
outstandingTask.cancel();
|
||||
outstandingTask.cancel(true);
|
||||
outstandingTask = null;
|
||||
}
|
||||
active = false;
|
||||
}
|
||||
|
||||
private final class AutoFocusTask extends AsyncTask<Void,Void,Void> {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
try {
|
||||
Thread.sleep(AUTO_FOCUS_INTERVAL_MS);
|
||||
} catch (InterruptedException e) {
|
||||
// continue
|
||||
}
|
||||
synchronized (AutoFocusManager.this) {
|
||||
if (active) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue