Skip to content

Commit

Permalink
Merge pull request #60 from dlazaro66/update_zxing_additional_files
Browse files Browse the repository at this point in the history
Update zxing additional files
  • Loading branch information
saguinav authored Jul 31, 2016
2 parents 83cd037 + a47628f commit 8a126e3
Show file tree
Hide file tree
Showing 17 changed files with 622 additions and 612 deletions.
6 changes: 3 additions & 3 deletions qrcodereaderview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
buildToolsVersion "21.1.2"

defaultConfig {
minSdkVersion 8
targetSdkVersion 21
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName version
}
Expand All @@ -30,6 +30,6 @@ android {
}

dependencies {
compile 'com.google.zxing:core:3.2.1'
compile 'com.dlazaro66.qrcodereaderview:qrcodereaderview:1.0.0'
}

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.google.zxing.PlanarYUVLuminanceSource;
import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import com.google.zxing.client.android.camera.open.CameraManager;
import com.google.zxing.client.android.camera.CameraManager;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,33 @@
* 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.
*
* -- Class modifications
*
* Copyright 2016 David Lázaro Esparcia.
*
* 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.camera.open;
package com.google.zxing.client.android.camera;

import android.content.Context;
import android.hardware.Camera;
import android.os.AsyncTask;
import android.util.Log;
import com.google.zxing.client.android.common.executor.AsyncTaskExecInterface;
import com.google.zxing.client.android.common.executor.AsyncTaskExecManager;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.RejectedExecutionException;

final class AutoFocusManager implements Camera.AutoFocusCallback {

Expand All @@ -33,63 +48,80 @@ final class AutoFocusManager implements Camera.AutoFocusCallback {
private static final Collection<String> FOCUS_MODES_CALLING_AF;

static {
FOCUS_MODES_CALLING_AF = new ArrayList<String>(2);
FOCUS_MODES_CALLING_AF = new ArrayList<>(2);
FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_AUTO);
FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_MACRO);
}

private boolean active;
private boolean stopped;
private boolean focusing;
private final boolean useAutoFocus;
private final Camera camera;
private AutoFocusTask outstandingTask;
private final AsyncTaskExecInterface taskExec;
private AsyncTask<?, ?, ?> outstandingTask;

AutoFocusManager(Context context, Camera camera) {
this.camera = camera;
taskExec = new AsyncTaskExecManager().build();
//SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); // No need to get SharedPreferences
String currentFocusMode = camera.getParameters().getFocusMode();
useAutoFocus =
/*sharedPrefs.getBoolean(PreferencesActivity.KEY_AUTO_FOCUS, true) &&*/
// No need to get SharedPreferences
FOCUS_MODES_CALLING_AF.contains(currentFocusMode);
useAutoFocus = FOCUS_MODES_CALLING_AF.contains(currentFocusMode);
Log.i(TAG, "Current focus mode '" + currentFocusMode + "'; use auto focus? " + useAutoFocus);
start();
}

@Override public synchronized void onAutoFocus(boolean success, Camera theCamera) {
if (active) {
outstandingTask = new AutoFocusTask();
taskExec.execute(outstandingTask);
focusing = false;
autoFocusAgainLater();
}

private synchronized void autoFocusAgainLater() {
if (!stopped && outstandingTask == null) {
AutoFocusTask newTask = new AutoFocusTask();
try {
newTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
outstandingTask = newTask;
} catch (RejectedExecutionException ree) {
Log.w(TAG, "Could not request auto focus", ree);
}
}
}

synchronized void start() {
if (useAutoFocus) {
active = true;
try {
camera.autoFocus(this);
} catch (RuntimeException re) {
// Have heard RuntimeException reported in Android 4.0.x+; continue?
Log.w(TAG, "Unexpected exception while focusing", re);
outstandingTask = null;
if (!stopped && !focusing) {
try {
camera.autoFocus(this);
focusing = true;
} catch (RuntimeException re) {
// Have heard RuntimeException reported in Android 4.0.x+; continue?
Log.w(TAG, "Unexpected exception while focusing", re);
// Try again later to keep cycle going
autoFocusAgainLater();
}
}
}
}

private synchronized void cancelOutstandingTask() {
if (outstandingTask != null) {
if (outstandingTask.getStatus() != AsyncTask.Status.FINISHED) {
outstandingTask.cancel(true);
}
outstandingTask = null;
}
}

synchronized void stop() {
stopped = true;
if (useAutoFocus) {
cancelOutstandingTask();
// Doesn't hurt to call this even if not focusing
try {
camera.cancelAutoFocus();
} catch (RuntimeException re) {
// Have heard RuntimeException reported in Android 4.0.x+; continue?
Log.w(TAG, "Unexpected exception while cancelling focusing", re);
}
}
if (outstandingTask != null) {
outstandingTask.cancel(true);
outstandingTask = null;
}
active = false;
}

private final class AutoFocusTask extends AsyncTask<Object, Object, Object> {
Expand All @@ -99,11 +131,7 @@ private final class AutoFocusTask extends AsyncTask<Object, Object, Object> {
} catch (InterruptedException e) {
// continue
}
synchronized (AutoFocusManager.this) {
if (active) {
start();
}
}
start();
return null;
}
}
Expand Down
Loading

0 comments on commit 8a126e3

Please sign in to comment.