mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-09 00:37:59 -06:00
Reformat reciever
This commit is contained in:
@@ -66,10 +66,10 @@ dependencies {
|
|||||||
androidTestImplementation(libs.espresso.core)
|
androidTestImplementation(libs.espresso.core)
|
||||||
|
|
||||||
|
|
||||||
var camerax_version = "1.3.2"
|
var camerax_version = "1.4.2"
|
||||||
implementation("androidx.camera:camera-core:1.3.2")
|
implementation("androidx.camera:camera-core:${camerax_version}")
|
||||||
implementation("androidx.camera:camera-camera2:1.3.2")
|
implementation("androidx.camera:camera-camera2:${camerax_version}")
|
||||||
implementation("androidx.camera:camera-lifecycle:1.3.2")
|
implementation("androidx.camera:camera-lifecycle:${camerax_version}")
|
||||||
implementation("androidx.camera:camera-view:${camerax_version}")
|
implementation("androidx.camera:camera-view:${camerax_version}")
|
||||||
|
|
||||||
implementation("com.journeyapps:zxing-android-embedded:4.3.0")
|
implementation("com.journeyapps:zxing-android-embedded:4.3.0")
|
||||||
|
|||||||
+36
-26
@@ -6,6 +6,7 @@ import android.Manifest;
|
|||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Matrix;
|
||||||
import android.media.Image;
|
import android.media.Image;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -40,10 +41,13 @@ 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 com.ridgebotics.ridgescout.utility.TaskRunner;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.units.qual.C;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@@ -63,21 +67,12 @@ public class CodeScannerView extends Fragment {
|
|||||||
alert.create().show();
|
alert.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private float scale = 0;
|
|
||||||
private final int downscale = 1;
|
private final int downscale = 1;
|
||||||
private LifecycleOwner lifecycle;
|
private LifecycleOwner lifecycle;
|
||||||
|
|
||||||
private void setImage(Bitmap bmp){
|
private void setImage(Bitmap bmp){
|
||||||
if(scale == 0) {
|
|
||||||
scale = ((float) binding.container.getWidth() / bmp.getWidth()) * ((float) 16 / 9);
|
|
||||||
binding.scannerImage.setTranslationX(0);
|
|
||||||
binding.scannerImage.setTranslationY(0);
|
|
||||||
}
|
|
||||||
scanQRCode(bmp);
|
scanQRCode(bmp);
|
||||||
binding.scannerImage.setImageBitmap(bmp);
|
binding.scannerImage.setImageBitmap(bmp);
|
||||||
binding.scannerThreshold.bringToFront();
|
|
||||||
// alert("test", getChildCount()+"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private Bitmap img
|
// private Bitmap img
|
||||||
@@ -100,15 +95,20 @@ public class CodeScannerView extends Fragment {
|
|||||||
final int height = image.getHeight();
|
final int height = image.getHeight();
|
||||||
|
|
||||||
int[] pixels = new int[width * height];
|
int[] pixels = new int[width * height];
|
||||||
for (int y = 0; y < height; y++) {
|
for (int i = 0; i < width*height; i++) {
|
||||||
for (int x = 0; x < width; x++) {
|
int L = levelMap[yBuffer.get(i) & 0xff];
|
||||||
int L = levelMap[yBuffer.get() & 0xff];
|
pixels[i] = 0xff000000 | (L << 16) | (L << 8) | L;
|
||||||
pixels[y * width + x] = 0xff000000 | (L << 16) | (L << 8) | L;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Matrix matrix = new Matrix();
|
||||||
|
|
||||||
|
matrix.postRotate(90);
|
||||||
|
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||||
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
|
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
|
||||||
|
bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
|
||||||
|
// Bitmap.rota
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
@@ -228,26 +228,23 @@ public class CodeScannerView extends Fragment {
|
|||||||
|
|
||||||
void bindPreview(@NonNull ProcessCameraProvider cameraProvider) {
|
void bindPreview(@NonNull ProcessCameraProvider cameraProvider) {
|
||||||
|
|
||||||
Preview preview = new Preview.Builder()
|
Preview preview = new Preview.Builder().build();
|
||||||
.setTargetAspectRatio(AspectRatio.RATIO_16_9)
|
|
||||||
.setTargetRotation(Surface.ROTATION_180)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
CameraSelector cameraSelector = new CameraSelector.Builder()
|
CameraSelector cameraSelector = new CameraSelector.Builder()
|
||||||
.requireLensFacing(CameraSelector.LENS_FACING_BACK)
|
.requireLensFacing(CameraSelector.LENS_FACING_BACK)
|
||||||
|
|
||||||
// .addCameraFilter(CameraFilters.NON)
|
// .addCameraFilter(CameraFilters.NON)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
|
ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
|
||||||
// .setTargetResolution(new Size(224, 224))
|
// .setTargetAspectRatio(AspectRatio.RATIO_16_9)
|
||||||
.setOutputImageRotationEnabled(false)
|
|
||||||
.setTargetAspectRatio(AspectRatio.RATIO_16_9)
|
|
||||||
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
|
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
|
||||||
|
// .setOutputImageRotationEnabled(true)
|
||||||
|
// .setTargetRotation(Surface.ROTATION_0)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
||||||
imageAnalysis.setAnalyzer(executor, new ImageAnalysis.Analyzer() {
|
imageAnalysis.setAnalyzer(executor, new ImageAnalysis.Analyzer() {
|
||||||
@OptIn(markerClass = ExperimentalGetImage.class) @Override
|
@OptIn(markerClass = ExperimentalGetImage.class) @Override
|
||||||
public void analyze(@NonNull ImageProxy image) {
|
public void analyze(@NonNull ImageProxy image) {
|
||||||
@@ -266,6 +263,7 @@ public class CodeScannerView extends Fragment {
|
|||||||
});
|
});
|
||||||
|
|
||||||
cameraProvider.unbindAll();
|
cameraProvider.unbindAll();
|
||||||
|
// cameraProvider.ro
|
||||||
|
|
||||||
cameraProvider.bindToLifecycle(lifecycle,
|
cameraProvider.bindToLifecycle(lifecycle,
|
||||||
cameraSelector, imageAnalysis, preview);
|
cameraSelector, imageAnalysis, preview);
|
||||||
@@ -292,6 +290,7 @@ public class CodeScannerView extends Fragment {
|
|||||||
Log.i("title", ""+qrCount);
|
Log.i("title", ""+qrCount);
|
||||||
barColors = new int[qrCount];
|
barColors = new int[qrCount];
|
||||||
prevQrIndex = qrIndex;
|
prevQrIndex = qrIndex;
|
||||||
|
qrScannedCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean updated;
|
final boolean updated;
|
||||||
@@ -310,8 +309,20 @@ public class CodeScannerView extends Fragment {
|
|||||||
|
|
||||||
if(updated && qrScannedCount >= qrCount){
|
if(updated && qrScannedCount >= qrCount){
|
||||||
|
|
||||||
|
AlertManager.startLoading("Decoding data...");
|
||||||
|
new TaskRunner().executeAsync(new CodeDecodeTask(), result -> {
|
||||||
|
AlertManager.stopLoading();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
prevQrIndex = qrIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class CodeDecodeTask implements Callable<Void> {
|
||||||
|
@Override
|
||||||
|
public Void call() {
|
||||||
String compiledString = "";
|
String compiledString = "";
|
||||||
for(int i=0;i<qrCount;i++){
|
for(int i=0;i<qrDataArr.length;i++){
|
||||||
compiledString += qrDataArr[i];
|
compiledString += qrDataArr[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,9 +350,8 @@ public class CodeScannerView extends Fragment {
|
|||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
AlertManager.error(e);
|
AlertManager.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
prevQrIndex = qrIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public final class FileEditor {
|
|||||||
|
|
||||||
|
|
||||||
public static int byteFromChar(char c){
|
public static int byteFromChar(char c){
|
||||||
byte[] bytes = (String.valueOf(c)).getBytes(Charset.defaultCharset());
|
byte[] bytes = (String.valueOf(c)).getBytes(StandardCharsets.ISO_8859_1);
|
||||||
return Byte.toUnsignedInt(bytes[0]);
|
return Byte.toUnsignedInt(bytes[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,77 +7,65 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/scannerColors"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="48dp"
|
|
||||||
android:layout_marginTop="15dp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/scannerThreshold"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="48dp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/scannerColors" />
|
|
||||||
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/scannerBrightness"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="48dp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/scannerThreshold" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/scannerColorsLabel"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="8dp"
|
|
||||||
android:layout_marginBottom="-12dp"
|
|
||||||
android:text="Posterize"
|
|
||||||
app:layout_constraintBottom_toTopOf="@+id/scannerColors"
|
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/scannerThresholdLabel"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="8dp"
|
|
||||||
android:layout_marginBottom="-12dp"
|
|
||||||
android:text="Exposure"
|
|
||||||
app:layout_constraintBottom_toTopOf="@+id/scannerThreshold"
|
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/scannerBrightnessLabel"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="8dp"
|
|
||||||
android:layout_marginBottom="-12dp"
|
|
||||||
android:text="Brightness"
|
|
||||||
app:layout_constraintBottom_toTopOf="@+id/scannerBrightness"
|
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
|
||||||
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/scannerImage"
|
android:id="@+id/scannerImage"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:rotation="90"
|
|
||||||
android:scaleType="fitCenter"
|
android:scaleType="fitCenter"
|
||||||
android:scaleX="1"
|
|
||||||
android:scaleY="1"
|
|
||||||
android:translationY="-40dp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
tools:context=".CodeScannerView" />
|
tools:context=".CodeScannerView" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="3dp"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:background="@drawable/border"
|
||||||
|
android:orientation="vertical"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
tools:layout_editor_absoluteX="3dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/scannerColorsLabel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Posterize"
|
||||||
|
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"/>
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/scannerColors"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_marginTop="15dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/scannerThresholdLabel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Exposure"
|
||||||
|
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"/>
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/scannerThreshold"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="48dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/scannerBrightnessLabel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Brightness"
|
||||||
|
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"/>
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/scannerBrightness"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="48dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Reference in New Issue
Block a user