Skip to content

Commit

Permalink
For #38: Initial (non-functional) prototype for ZXing
Browse files Browse the repository at this point in the history
  • Loading branch information
czlucius committed Feb 28, 2022
1 parent 0d169f8 commit f48e7f2
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Code Scanner. An android app to scan and create codes(barcodes, QR codes, etc)
* Copyright (C) 2021 Lucius Chee Zihan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.czlucius.scan.translators.zxing;

import com.czlucius.scan.objects.Code;
import com.czlucius.scan.objects.Type;
import com.czlucius.scan.translators.CodeTranslator;
import com.czlucius.scan.translators.TranslationException;
import com.google.zxing.Result;

public class ZXingCodeTranslator implements CodeTranslator<Result> {
@Override
public Code convert(Result from) throws TranslationException {

Code code = new Code()
return null;
}
}
22 changes: 22 additions & 0 deletions app/src/foss/java/com/czlucius/scan/utils/zxing/ZXingUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Code Scanner. An android app to scan and create codes(barcodes, QR codes, etc)
* Copyright (C) 2021 Lucius Chee Zihan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.czlucius.scan.utils.zxing;

public class ZXingUtils {
}
55 changes: 55 additions & 0 deletions app/src/main/java/com/czlucius/scan/objects/BaseAnalyser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Code Scanner. An android app to scan and create codes(barcodes, QR codes, etc)
* Copyright (C) 2021 Lucius Chee Zihan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.czlucius.scan.objects;

import androidx.annotation.NonNull;
import androidx.camera.core.ImageAnalysis;
import androidx.camera.core.ImageProxy;

import java.util.List;

public abstract class BaseAnalyser implements ImageAnalysis.Analyzer {

private final SuccessCallback successCallback;
private final FailureHandler failureHandler;

protected BaseAnalyser(SuccessCallback successCallback, FailureHandler failureHandler) {
this.successCallback = successCallback;
this.failureHandler = failureHandler;
}


public abstract void analyze(@NonNull ImageProxy image, SuccessCallback successCallback, FailureHandler failureHandler);

@Override
public final void analyze(@NonNull ImageProxy imageProxy) {
analyze(imageProxy, successCallback, failureHandler);
imageProxy.close();
}


public interface SuccessCallback {
void scannedBarcodes(List<Code> barcodes);
}

public interface FailureHandler {
void handleException(Exception e);
}

}
2 changes: 1 addition & 1 deletion app/src/main/java/com/czlucius/scan/objects/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Code(Barcode barcode) {
timeScanned = new Date();
}

private Code(Type dataType, int format, Data data) {
public Code(Type dataType, int format, Data data) {
this.dataType = dataType;
this.format = format;
this.data = data;
Expand Down
26 changes: 26 additions & 0 deletions app/src/play/java/com/czlucius/scan/MLKitUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Code Scanner. An android app to scan and create codes(barcodes, QR codes, etc)
* Copyright (C) 2021 Lucius Chee Zihan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.czlucius.scan;

import com.czlucius.scan.objects.Type;
import com.google.mlkit.vision.barcode.common.Barcode;

public class MLKitUtils {

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

import java.util.List;

/**
* Main analysing is done here.
*/
public class CodeAnalyser implements ImageAnalysis.Analyzer {

private SuccessCallback mCallBack;
Expand All @@ -57,7 +60,7 @@ public void analyze(@NonNull ImageProxy imageProxy) {
Image barcodeImage = imageProxy.getImage();
if (barcodeImage != null) {
InputImage inputImage = InputImage.fromMediaImage(barcodeImage, imageProxy.getImageInfo().getRotationDegrees());
//Pass to ML Kit API
//Pass to API

BarcodeScanner barcodeScanner = BarcodeScanning.getClient();
Task<List<Barcode>> result = barcodeScanner.process(inputImage)
Expand Down

0 comments on commit f48e7f2

Please sign in to comment.