mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-08 16:28:00 -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.common.HybridBinarizer;
|
||||
import com.google.zxing.datamatrix.DataMatrixReader;
|
||||
import com.ridgebotics.ridgescout.utility.TaskRunner;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
|
||||
// Background task for code scanning, to not slow down the scanner.
|
||||
public class CodeScanTask extends AsyncTask<String, String, String>{
|
||||
private Function<String, String> resultFunction = null;
|
||||
//public class CodeScanTask extends AsyncTask<String, String, String>{
|
||||
// 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;
|
||||
|
||||
public CodeScanTask(Bitmap image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... str) {
|
||||
public String call() {
|
||||
if(image == null){return null;}
|
||||
|
||||
int width = image.getWidth();
|
||||
@@ -52,17 +102,4 @@ public class CodeScanTask extends AsyncTask<String, String, String>{
|
||||
|
||||
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.FileEditor;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.ridgebotics.ridgescout.utility.TaskRunner;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -113,9 +114,8 @@ public class CodeScannerView extends Fragment {
|
||||
}
|
||||
public void scanQRCode(Bitmap bitmap) {
|
||||
|
||||
CodeScanTask async = new CodeScanTask();
|
||||
async.setImage(bitmap);
|
||||
async.onResult(data -> {
|
||||
// CodeScanTask async = new CodeScanTask();
|
||||
new TaskRunner().executeAsync(new CodeScanTask(bitmap), data -> {
|
||||
if(data != null){
|
||||
// alert("test", ""+fileEditor.byteFromChar(data.charAt(0)));
|
||||
compileData(
|
||||
@@ -126,10 +126,7 @@ public class CodeScannerView extends Fragment {
|
||||
data.substring(4)
|
||||
);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
async.execute();
|
||||
|
||||
|
||||
|
||||
// return contents;
|
||||
|
||||
Reference in New Issue
Block a user