diff --git a/android/src/com/google/zxing/client/android/FinishListener.java b/android/src/com/google/zxing/client/android/FinishListener.java index 0a471dbd1..5d5988619 100644 --- a/android/src/com/google/zxing/client/android/FinishListener.java +++ b/android/src/com/google/zxing/client/android/FinishListener.java @@ -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(); } diff --git a/android/src/com/google/zxing/client/android/camera/AutoFocusManager.java b/android/src/com/google/zxing/client/android/camera/AutoFocusManager.java index 4e7e543d3..0f30b62f4 100644 --- a/android/src/com/google/zxing/client/android/camera/AutoFocusManager.java +++ b/android/src/com/google/zxing/client/android/camera/AutoFocusManager.java @@ -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 { + @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; + } + } + }