mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-09 00:37:59 -06:00
Use DataMatrix codes, they are much faster. Start work on storing settings
This commit is contained in:
+51
@@ -0,0 +1,51 @@
|
|||||||
|
package com.astatin3.scoutingapp2025.SettingsVersionStack;
|
||||||
|
|
||||||
|
import com.astatin3.scoutingapp2025.fileEditor;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public abstract class settingsVersion {
|
||||||
|
private static String settingsFilename = "settings.txt";
|
||||||
|
public abstract int getVersion();
|
||||||
|
public abstract void update();
|
||||||
|
|
||||||
|
public static String readLine(int line){
|
||||||
|
if(!fileEditor.fileExist("settings.txt")){return null;}
|
||||||
|
|
||||||
|
String[] fileContent = new String(fileEditor.readFile("settings.txt"), StandardCharsets.UTF_8).split("\n");
|
||||||
|
|
||||||
|
if(fileContent.length <= line){return null;}
|
||||||
|
|
||||||
|
return fileContent[line];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String w riteLine(int line, String data){
|
||||||
|
String[] fileContent;
|
||||||
|
if(!fileEditor.fileExist(settingsFilename)){
|
||||||
|
fileContent = new String[]{};
|
||||||
|
}else{
|
||||||
|
fileContent = new String(fileEditor.readFile(settingsFilename), StandardCharsets.UTF_8).split("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
String newFile = "";
|
||||||
|
|
||||||
|
for(int i = 0; i < Math.max(fileContent.length-1, line); i++){
|
||||||
|
|
||||||
|
if(i == line) {
|
||||||
|
newFile += data + "\n";
|
||||||
|
|
||||||
|
}else if(i > fileContent.length-1){
|
||||||
|
newFile += fileContent[i];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i < Math.max(fileContent.length - 1, line) - 1){
|
||||||
|
newFile += "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newFile;
|
||||||
|
|
||||||
|
// fileEditor.writeFile(settingsFilename, newFile.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.astatin3.scoutingapp2025.SettingsVersionStack;
|
||||||
|
|
||||||
|
public class v0 extends settingsVersion {
|
||||||
|
@Override
|
||||||
|
public int getVersion() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-3
@@ -12,7 +12,11 @@ import com.google.zxing.NotFoundException;
|
|||||||
import com.google.zxing.RGBLuminanceSource;
|
import com.google.zxing.RGBLuminanceSource;
|
||||||
import com.google.zxing.Reader;
|
import com.google.zxing.Reader;
|
||||||
import com.google.zxing.Result;
|
import com.google.zxing.Result;
|
||||||
|
import com.google.zxing.aztec.AztecReader;
|
||||||
import com.google.zxing.common.HybridBinarizer;
|
import com.google.zxing.common.HybridBinarizer;
|
||||||
|
import com.google.zxing.datamatrix.DataMatrixReader;
|
||||||
|
import com.google.zxing.maxicode.MaxiCodeReader;
|
||||||
|
import com.google.zxing.pdf417.PDF417Reader;
|
||||||
import com.google.zxing.qrcode.QRCodeReader;
|
import com.google.zxing.qrcode.QRCodeReader;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
@@ -20,7 +24,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class qrScanTask 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;
|
private Bitmap image;
|
||||||
|
|
||||||
@@ -39,9 +43,9 @@ public class qrScanTask extends AsyncTask<String, String, String>{
|
|||||||
Map<DecodeHintType, Object> hints = new HashMap<>();
|
Map<DecodeHintType, Object> hints = new HashMap<>();
|
||||||
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
|
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
|
||||||
// hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
|
// hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
|
||||||
hints.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.of(BarcodeFormat.QR_CODE));
|
hints.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.of(BarcodeFormat.DATA_MATRIX));
|
||||||
|
|
||||||
Reader reader = new QRCodeReader();
|
Reader reader = new DataMatrixReader();
|
||||||
try {
|
try {
|
||||||
Result result = reader.decode(binaryBitmap, hints);
|
Result result = reader.decode(binaryBitmap, hints);
|
||||||
return result.getText();
|
return result.getText();
|
||||||
@@ -3,7 +3,6 @@ package com.astatin3.scoutingapp2025;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.astatin3.scoutingapp2025.types.frcEvent;
|
import com.astatin3.scoutingapp2025.types.frcEvent;
|
||||||
import com.astatin3.scoutingapp2025.types.frcMatch;
|
|
||||||
import com.astatin3.scoutingapp2025.types.frcTeam;
|
import com.astatin3.scoutingapp2025.types.frcTeam;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
@@ -13,7 +12,6 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.nio.BufferOverflowException;
|
import java.nio.BufferOverflowException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -44,7 +42,7 @@ public final class fileEditor {
|
|||||||
|
|
||||||
|
|
||||||
public static char byteToChar(int num){
|
public static char byteToChar(int num){
|
||||||
return new String(toBytes(num, 1), StandardCharsets.UTF_8).charAt(0);
|
return new String(toBytes(num, 1), StandardCharsets.ISO_8859_1).charAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -125,7 +123,7 @@ public final class fileEditor {
|
|||||||
return outputStream.toByteArray();
|
return outputStream.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean writeToFile(String filepath, byte[] data) {
|
public static boolean writeFile(String filepath, byte[] data) {
|
||||||
try {
|
try {
|
||||||
FileOutputStream output = new FileOutputStream(filepath);
|
FileOutputStream output = new FileOutputStream(filepath);
|
||||||
output.write(data);
|
output.write(data);
|
||||||
@@ -138,8 +136,13 @@ public final class fileEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean fileExist(String path){
|
||||||
|
File f = new File(baseDir + path);
|
||||||
|
return f.exists() && !f.isDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] readFile(String path){
|
public static byte[] readFile(String path){
|
||||||
File file = new File(path);
|
File file = new File(baseDir + path);
|
||||||
int size = (int) file.length();
|
int size = (int) file.length();
|
||||||
byte[] bytes = new byte[size];
|
byte[] bytes = new byte[size];
|
||||||
try {
|
try {
|
||||||
@@ -176,7 +179,7 @@ public final class fileEditor {
|
|||||||
public static boolean setEvent(frcEvent event){
|
public static boolean setEvent(frcEvent event){
|
||||||
final String filename = (baseDir + event.eventCode + ".eventdata");
|
final String filename = (baseDir + event.eventCode + ".eventdata");
|
||||||
|
|
||||||
return writeToFile(filename, event.encode());
|
return writeFile(filename, event.encode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<String> getEventList(){
|
public static ArrayList<String> getEventList(){
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import androidx.fragment.app.Fragment;
|
|||||||
|
|
||||||
import com.astatin3.scoutingapp2025.databinding.FragmentSettingsBinding;
|
import com.astatin3.scoutingapp2025.databinding.FragmentSettingsBinding;
|
||||||
import com.astatin3.scoutingapp2025.fileEditor;
|
import com.astatin3.scoutingapp2025.fileEditor;
|
||||||
|
import com.astatin3.scoutingapp2025.SettingsVersionStack.v0;
|
||||||
|
|
||||||
import com.skydoves.powerspinner.IconSpinnerAdapter;
|
import com.skydoves.powerspinner.IconSpinnerAdapter;
|
||||||
import com.skydoves.powerspinner.IconSpinnerItem;
|
import com.skydoves.powerspinner.IconSpinnerItem;
|
||||||
import com.skydoves.powerspinner.PowerSpinnerView;
|
import com.skydoves.powerspinner.PowerSpinnerView;
|
||||||
@@ -57,9 +59,17 @@ public class settingsFragment extends Fragment {
|
|||||||
IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(spinnerView);
|
IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(spinnerView);
|
||||||
spinnerView.setSpinnerAdapter(iconSpinnerAdapter);
|
spinnerView.setSpinnerAdapter(iconSpinnerAdapter);
|
||||||
spinnerView.setItems(iconSpinnerItems);
|
spinnerView.setItems(iconSpinnerItems);
|
||||||
spinnerView.selectItemByIndex(0);
|
|
||||||
spinnerView.setLifecycleOwner(this);
|
spinnerView.setLifecycleOwner(this);
|
||||||
|
|
||||||
|
if(!iconSpinnerItems.isEmpty()){
|
||||||
|
spinnerView.selectItemByIndex(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
alert("test", v0.writeLine(1, "oeseo"));
|
||||||
|
|
||||||
|
|
||||||
|
alert("test", v0.readLine(0));
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -40,7 +40,7 @@ public class generatorView extends ConstraintLayout {
|
|||||||
private final int minQrSpeed = 300 + maxQrSpeed - 1;
|
private final int minQrSpeed = 300 + maxQrSpeed - 1;
|
||||||
|
|
||||||
private int minQrSize = 0;
|
private int minQrSize = 0;
|
||||||
private final int maxQrSize = 500;
|
private final int maxQrSize = 800;
|
||||||
private int qrSize = 200;
|
private int qrSize = 200;
|
||||||
|
|
||||||
private final int defaultQrDelay = 419;
|
private final int defaultQrDelay = 419;
|
||||||
@@ -71,16 +71,17 @@ public class generatorView extends ConstraintLayout {
|
|||||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||||
|
|
||||||
// The Charset must be UTF-8, Or data will not be transferred properly. IDK why.
|
// The Charset must be UTF-8, Or data will not be transferred properly. IDK why.
|
||||||
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
hints.put(EncodeHintType.CHARACTER_SET, "ISO-8859-1");
|
||||||
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
|
// hints.put(EncodeHintType.);
|
||||||
hints.put(EncodeHintType.MARGIN, 0); /* default = 4 */
|
hints.put(EncodeHintType.MARGIN, 0); /* default = 4 */
|
||||||
MultiFormatWriter writer = new MultiFormatWriter();
|
MultiFormatWriter writer = new MultiFormatWriter();
|
||||||
|
|
||||||
BitMatrix result;
|
BitMatrix result;
|
||||||
try {
|
try {
|
||||||
result = writer.encode(contents, BarcodeFormat.QR_CODE, size, size, hints);
|
result = writer.encode(contents, BarcodeFormat.DATA_MATRIX, size, size, hints);
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException e) {
|
||||||
// Unsupported format
|
// Unsupported format
|
||||||
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +196,7 @@ public class generatorView extends ConstraintLayout {
|
|||||||
try {
|
try {
|
||||||
// alert("test", ""+Math.ceil((double)data.length()/(double)qrSize));
|
// alert("test", ""+Math.ceil((double)data.length()/(double)qrSize));
|
||||||
qrBitmaps.add(generateQrCode(
|
qrBitmaps.add(generateQrCode(
|
||||||
fileEditor.byteToChar(fileEditor.internalDataVersion) +
|
fileEditor.byteToChar(fileEditor.internalDataVersion) +
|
||||||
String.valueOf(fileEditor.byteToChar(randID)) +
|
String.valueOf(fileEditor.byteToChar(randID)) +
|
||||||
fileEditor.byteToChar(i) +
|
fileEditor.byteToChar(i) +
|
||||||
fileEditor.byteToChar(qrCount - 1) +
|
fileEditor.byteToChar(qrCount - 1) +
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import android.widget.SeekBar;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.OptIn;
|
import androidx.annotation.OptIn;
|
||||||
import androidx.camera.core.AspectRatio;
|
import androidx.camera.core.AspectRatio;
|
||||||
import androidx.camera.core.Camera;
|
|
||||||
import androidx.camera.core.CameraSelector;
|
import androidx.camera.core.CameraSelector;
|
||||||
import androidx.camera.core.ExperimentalGetImage;
|
import androidx.camera.core.ExperimentalGetImage;
|
||||||
import androidx.camera.core.ImageAnalysis;
|
import androidx.camera.core.ImageAnalysis;
|
||||||
@@ -28,7 +27,7 @@ import androidx.lifecycle.LifecycleOwner;
|
|||||||
|
|
||||||
import com.astatin3.scoutingapp2025.databinding.FragmentTransferBinding;
|
import com.astatin3.scoutingapp2025.databinding.FragmentTransferBinding;
|
||||||
import com.astatin3.scoutingapp2025.fileEditor;
|
import com.astatin3.scoutingapp2025.fileEditor;
|
||||||
import com.astatin3.scoutingapp2025.qrScanTask;
|
import com.astatin3.scoutingapp2025.codeScanTask;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@@ -111,7 +110,7 @@ public class scannerView extends ConstraintLayout {
|
|||||||
}
|
}
|
||||||
public void scanQRCode(Bitmap bitmap) {
|
public void scanQRCode(Bitmap bitmap) {
|
||||||
|
|
||||||
qrScanTask async = new qrScanTask();
|
codeScanTask async = new codeScanTask();
|
||||||
async.setImage(bitmap);
|
async.setImage(bitmap);
|
||||||
async.onResult(data -> {
|
async.onResult(data -> {
|
||||||
if(data != null){
|
if(data != null){
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@color/black_2"
|
android:background="@color/black_2"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:hint="Question 1"
|
android:hint="Events"
|
||||||
android:padding="10dp"
|
android:padding="10dp"
|
||||||
android:textColor="@color/main_500"
|
android:textColor="@color/main_500"
|
||||||
android:textColorHint="@color/teal_700"
|
android:textColorHint="@color/teal_700"
|
||||||
|
|||||||
Reference in New Issue
Block a user