mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-09 00:37:59 -06:00
Remove asynctask from codescannertask
This commit is contained in:
@@ -14,19 +14,69 @@ import com.google.zxing.Reader;
|
|||||||
import com.google.zxing.Result;
|
import com.google.zxing.Result;
|
||||||
import com.google.zxing.common.HybridBinarizer;
|
import com.google.zxing.common.HybridBinarizer;
|
||||||
import com.google.zxing.datamatrix.DataMatrixReader;
|
import com.google.zxing.datamatrix.DataMatrixReader;
|
||||||
|
import com.ridgebotics.ridgescout.utility.TaskRunner;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
// Background task for code scanning, to not slow down the scanner.
|
// Background task for code scanning, to not slow down the scanner.
|
||||||
public class CodeScanTask extends AsyncTask<String, String, String>{
|
//public class CodeScanTask extends AsyncTask<String, String, String>{
|
||||||
private Function<String, String> resultFunction = null;
|
// private Function<String, String> resultFunction = null;
|
||||||
|
// private Bitmap image;
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// protected String doInBackground(String... str) {
|
||||||
|
// if(image == null){return null;}
|
||||||
|
//
|
||||||
|
// int width = image.getWidth();
|
||||||
|
// int height = image.getHeight();
|
||||||
|
// int[] pixels = new int[width * height];
|
||||||
|
// image.getPixels(pixels, 0, width, 0, 0, width, height);
|
||||||
|
//
|
||||||
|
// RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
|
||||||
|
// BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||||
|
//
|
||||||
|
// Map<DecodeHintType, Object> hints = new HashMap<>();
|
||||||
|
// hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
|
||||||
|
//// hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
|
||||||
|
// hints.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.of(BarcodeFormat.DATA_MATRIX));
|
||||||
|
//
|
||||||
|
// Reader reader = new DataMatrixReader();
|
||||||
|
// try {
|
||||||
|
// Result result = reader.decode(binaryBitmap, hints);
|
||||||
|
// return result.getText();
|
||||||
|
// } catch (NotFoundException | ChecksumException | FormatException e) {
|
||||||
|
//// AlertManager.error(e);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// public void setImage(Bitmap image){this.image = image;}
|
||||||
|
// public void onResult(Function<String, String> func) {
|
||||||
|
// this.resultFunction = func;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// protected void onPostExecute(String result) {
|
||||||
|
// super.onPostExecute(result);
|
||||||
|
// if(resultFunction != null){
|
||||||
|
// resultFunction.apply(result);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
public class CodeScanTask implements Callable<String> {
|
||||||
private Bitmap image;
|
private Bitmap image;
|
||||||
|
|
||||||
|
public CodeScanTask(Bitmap image) {
|
||||||
|
this.image = image;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(String... str) {
|
public String call() {
|
||||||
if(image == null){return null;}
|
if(image == null){return null;}
|
||||||
|
|
||||||
int width = image.getWidth();
|
int width = image.getWidth();
|
||||||
@@ -52,17 +102,4 @@ public class CodeScanTask extends AsyncTask<String, String, String>{
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public void setImage(Bitmap image){this.image = image;}
|
|
||||||
public void onResult(Function<String, String> func) {
|
|
||||||
this.resultFunction = func;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(String result) {
|
|
||||||
super.onPostExecute(result);
|
|
||||||
if(resultFunction != null){
|
|
||||||
resultFunction.apply(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import com.ridgebotics.ridgescout.utility.AlertManager;
|
|||||||
import com.ridgebotics.ridgescout.utility.BuiltByteParser;
|
import com.ridgebotics.ridgescout.utility.BuiltByteParser;
|
||||||
import com.ridgebotics.ridgescout.utility.FileEditor;
|
import com.ridgebotics.ridgescout.utility.FileEditor;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
import com.ridgebotics.ridgescout.utility.TaskRunner;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -113,9 +114,8 @@ public class CodeScannerView extends Fragment {
|
|||||||
}
|
}
|
||||||
public void scanQRCode(Bitmap bitmap) {
|
public void scanQRCode(Bitmap bitmap) {
|
||||||
|
|
||||||
CodeScanTask async = new CodeScanTask();
|
// CodeScanTask async = new CodeScanTask();
|
||||||
async.setImage(bitmap);
|
new TaskRunner().executeAsync(new CodeScanTask(bitmap), data -> {
|
||||||
async.onResult(data -> {
|
|
||||||
if(data != null){
|
if(data != null){
|
||||||
// alert("test", ""+fileEditor.byteFromChar(data.charAt(0)));
|
// alert("test", ""+fileEditor.byteFromChar(data.charAt(0)));
|
||||||
compileData(
|
compileData(
|
||||||
@@ -126,10 +126,7 @@ public class CodeScannerView extends Fragment {
|
|||||||
data.substring(4)
|
data.substring(4)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
});
|
});
|
||||||
async.execute();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// return contents;
|
// return contents;
|
||||||
|
|||||||
Reference in New Issue
Block a user