mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-09 00:37:59 -06:00
Problems with qr code system character encoding
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
package com.astatin3.scoutingapp2025.Utils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class frcEvent {
|
||||||
|
public String eventCode;
|
||||||
|
public String name;
|
||||||
|
public ArrayList<frcMatch> matches;
|
||||||
|
public ArrayList<frcTeam> teams;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.astatin3.scoutingapp2025.Utils;
|
||||||
|
|
||||||
|
public class frcMatch {
|
||||||
|
public frcMatch(){}
|
||||||
|
public int matchIndex = 0;
|
||||||
|
public int[] blueAlliance;
|
||||||
|
public int[] redAlliance;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.astatin3.scoutingapp2025.Utils;
|
||||||
|
|
||||||
|
public class frcTeam {
|
||||||
|
public int teamNumber = 0;
|
||||||
|
public String teamName = null;
|
||||||
|
public String city = null;
|
||||||
|
public String stateOrProv = null;
|
||||||
|
public String school = null;
|
||||||
|
public String country = null;
|
||||||
|
public int startingYear = 0;
|
||||||
|
|
||||||
|
public String getDescription(){
|
||||||
|
return teamName + " Started in " + startingYear + ", and is from " + school + " in " + city + ", " + stateOrProv + ", " + country;
|
||||||
|
}
|
||||||
|
|
||||||
|
public frcTeam encode(){
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public frcTeam decode(){
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package com.astatin3.scoutingapp2025;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.astatin3.scoutingapp2025.Utils.frcMatch;
|
||||||
|
import com.astatin3.scoutingapp2025.Utils.frcTeam;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.nio.BufferOverflowException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.zip.DataFormatException;
|
||||||
|
import java.util.zip.Deflater;
|
||||||
|
import java.util.zip.Inflater;
|
||||||
|
|
||||||
|
public final class fileEditor {
|
||||||
|
// private final static String baseDir = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
|
||||||
|
public static final byte internalDataVersion = 0x01;
|
||||||
|
|
||||||
|
public static String binaryVisualize(byte[] bytes){
|
||||||
|
String returnStr = "";
|
||||||
|
for(int a=0;a<bytes.length;a++){
|
||||||
|
for(int b=0;b<8;b++){
|
||||||
|
returnStr += String.valueOf((bytes[a] >> b) & 1);
|
||||||
|
}
|
||||||
|
returnStr += " (" + (int)bytes[a] + ")\n";
|
||||||
|
}
|
||||||
|
return returnStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static char toChar(int num){
|
||||||
|
if(num < 0 || num > 255){
|
||||||
|
throw new BufferOverflowException();
|
||||||
|
}
|
||||||
|
byte[] bytes = new byte[1];
|
||||||
|
bytes[0] = (byte) num;
|
||||||
|
return new String(bytes, Charset.defaultCharset()).charAt(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int fromChar(char c){
|
||||||
|
byte[] bytes = (String.valueOf(c)).getBytes(Charset.defaultCharset());
|
||||||
|
return Byte.toUnsignedInt(bytes[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] compress(byte[] input) {
|
||||||
|
Deflater deflater = new Deflater();
|
||||||
|
deflater.setInput(input);
|
||||||
|
deflater.finish();
|
||||||
|
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
|
||||||
|
while (!deflater.finished()) {
|
||||||
|
int compressedSize = deflater.deflate(buffer);
|
||||||
|
outputStream.write(buffer, 0, compressedSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static byte[] decompress(byte[] input) throws DataFormatException {
|
||||||
|
Inflater inflater = new Inflater();
|
||||||
|
inflater.setInput(input);
|
||||||
|
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
|
||||||
|
while (!inflater.finished()) {
|
||||||
|
int decompressedSize = inflater.inflate(buffer);
|
||||||
|
outputStream.write(buffer, 0, decompressedSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean writeToFile(Context context, String filepath, String data) {
|
||||||
|
try {
|
||||||
|
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput(filepath, Context.MODE_PRIVATE));
|
||||||
|
outputStreamWriter.write(data);
|
||||||
|
outputStreamWriter.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String intSplit(int[] intArr, String splitStr){
|
||||||
|
String returnStr = "";
|
||||||
|
for(int i=0;i<intArr.length;i++){
|
||||||
|
returnStr += String.valueOf(intArr[i]);
|
||||||
|
if(i != intArr.length-1){
|
||||||
|
returnStr += splitStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean setMatches(Context context, String key, String matchName, ArrayList<frcMatch> matches){
|
||||||
|
final String filename = (key + "-matches.csv");
|
||||||
|
|
||||||
|
String csvData = "";
|
||||||
|
|
||||||
|
csvData += key + "\n";
|
||||||
|
csvData += matchName + "\n";
|
||||||
|
|
||||||
|
for(int i=0;i<matches.size();i++){
|
||||||
|
final frcMatch match = matches.get(i);
|
||||||
|
csvData += String.valueOf(match.matchIndex)
|
||||||
|
+ "," + intSplit(match.redAlliance, ",")
|
||||||
|
+ "," + intSplit(match.blueAlliance, ",") + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return writeToFile(context, filename, csvData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean setTeams(Context context, String key, ArrayList<frcTeam> teams){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -2,12 +2,8 @@ package com.astatin3.scoutingapp2025.ui.transfer;
|
|||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -16,31 +12,26 @@ import android.widget.TableLayout;
|
|||||||
import android.widget.TableRow;
|
import android.widget.TableRow;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
||||||
import androidx.constraintlayout.widget.ConstraintSet;
|
|
||||||
|
|
||||||
import com.astatin3.scoutingapp2025.R;
|
|
||||||
import com.astatin3.scoutingapp2025.RequestTask;
|
import com.astatin3.scoutingapp2025.RequestTask;
|
||||||
import com.astatin3.scoutingapp2025.databinding.FragmentTbaBinding;
|
import com.astatin3.scoutingapp2025.Utils.frcMatch;
|
||||||
|
import com.astatin3.scoutingapp2025.Utils.frcTeam;
|
||||||
import com.astatin3.scoutingapp2025.databinding.FragmentTransferBinding;
|
import com.astatin3.scoutingapp2025.databinding.FragmentTransferBinding;
|
||||||
|
import com.astatin3.scoutingapp2025.fileEditor;
|
||||||
import com.astatin3.scoutingapp2025.ui.JSONUtil;
|
import com.astatin3.scoutingapp2025.ui.JSONUtil;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.w3c.dom.Text;
|
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class TBAView extends ScrollView {
|
public class TBAView extends ScrollView {
|
||||||
|
|
||||||
// private final String
|
|
||||||
private final String TBAAddress = "https://www.thebluealliance.com/api/v3/";
|
private final String TBAAddress = "https://www.thebluealliance.com/api/v3/";
|
||||||
private final String TBAHeader = "X-TBA-Auth-Key: tjEKSZojAU2pgbs2mBt06SKyOakVhLutj3NwuxLTxPKQPLih11aCIwRIVFXKzY4e";
|
private final String TBAHeader = "X-TBA-Auth-Key: tjEKSZojAU2pgbs2mBt06SKyOakVhLutj3NwuxLTxPKQPLih11aCIwRIVFXKzY4e";
|
||||||
|
|
||||||
@@ -68,6 +59,12 @@ public class TBAView extends ScrollView {
|
|||||||
|
|
||||||
Table = binding.matchTable;
|
Table = binding.matchTable;
|
||||||
|
|
||||||
|
Table.setStretchAllColumns(true);
|
||||||
|
|
||||||
|
TableRow tr = new TableRow(getContext());
|
||||||
|
addTableText(tr, "Loading Events...");
|
||||||
|
Table.addView(tr);
|
||||||
|
|
||||||
final RequestTask rq = new RequestTask();
|
final RequestTask rq = new RequestTask();
|
||||||
rq.onResult(new Function<String, String>() {
|
rq.onResult(new Function<String, String>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -89,6 +86,10 @@ public class TBAView extends ScrollView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void eventTable(String dataString){
|
public void eventTable(String dataString){
|
||||||
|
Table.removeAllViews();
|
||||||
|
Table.setStretchAllColumns(true);
|
||||||
|
Table.bringToFront();
|
||||||
|
|
||||||
Date currentTime = Calendar.getInstance().getTime();
|
Date currentTime = Calendar.getInstance().getTime();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -158,15 +159,35 @@ public class TBAView extends ScrollView {
|
|||||||
tr.setOnClickListener( new View.OnClickListener() {
|
tr.setOnClickListener( new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
Table.removeAllViews();
|
||||||
|
Table.setStretchAllColumns(true);
|
||||||
|
Table.bringToFront();
|
||||||
|
|
||||||
|
TableRow tr = new TableRow(getContext());
|
||||||
|
addTableText(tr, "Downloading Teams...");
|
||||||
|
Table.addView(tr);
|
||||||
|
|
||||||
final RequestTask rq = new RequestTask();
|
final RequestTask rq = new RequestTask();
|
||||||
rq.onResult(new Function<String, String>() {
|
rq.onResult(new Function<String, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String apply(String s) {
|
public String apply(String teamsStr) {
|
||||||
matchTable(s);
|
TableRow tr = new TableRow(getContext());
|
||||||
|
addTableText(tr, "Downloading Matches...");
|
||||||
|
Table.addView(tr);
|
||||||
|
|
||||||
|
final RequestTask rq = new RequestTask();
|
||||||
|
rq.onResult(new Function<String, String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(String matchesStr) {
|
||||||
|
matchTable(matchesStr, teamsStr, j);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
rq.execute((TBAAddress + "event/" + matchKey + "/matches"), TBAHeader);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
rq.execute((TBAAddress + "event/" + matchKey + "/matches"), TBAHeader);
|
rq.execute((TBAAddress + "event/" + matchKey + "/teams"), TBAHeader);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -194,17 +215,46 @@ public class TBAView extends ScrollView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void matchTable(String dataString){
|
|
||||||
|
public void matchTable(String matchesString, String teamsString, JSONObject eventData){
|
||||||
|
Table.removeAllViews();
|
||||||
|
Table.setStretchAllColumns(true);
|
||||||
|
Table.bringToFront();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONArray data = new JSONArray(dataString);
|
final JSONArray matchData = new JSONArray(matchesString);
|
||||||
|
final JSONArray teamData = new JSONArray(teamsString);
|
||||||
|
|
||||||
Table.removeAllViews();
|
String matchKey = eventData.getString("key");
|
||||||
Table.setStretchAllColumns(true);
|
String matchName = eventData.getString("short_name");
|
||||||
Table.bringToFront();
|
|
||||||
|
|
||||||
|
// Sometimes, a short name is not present on TBA Events
|
||||||
|
if(matchName.isEmpty()){
|
||||||
|
matchName = eventData.getString("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Event code at top
|
||||||
|
TextView tv = new TextView(getContext());
|
||||||
|
tv.setLayoutParams(new LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
));
|
||||||
|
tv.setText(matchKey);
|
||||||
|
tv.setTextSize(18);
|
||||||
|
Table.addView(tv);
|
||||||
|
|
||||||
if(data.length() == 0){
|
// Event Name
|
||||||
|
tv = new TextView(getContext());
|
||||||
|
tv.setLayoutParams(new LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
));
|
||||||
|
tv.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||||
|
tv.setText(matchName);
|
||||||
|
tv.setTextSize(28);
|
||||||
|
Table.addView(tv);
|
||||||
|
|
||||||
|
if(matchData.length() == 0){
|
||||||
TableRow tr = new TableRow(getContext());
|
TableRow tr = new TableRow(getContext());
|
||||||
addTableText(tr, "This event has no matches released yet...");
|
addTableText(tr, "This event has no matches released yet...");
|
||||||
Table.addView(tr);
|
Table.addView(tr);
|
||||||
@@ -214,7 +264,7 @@ public class TBAView extends ScrollView {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TableRow tr = new TableRow(getContext());
|
// Save button
|
||||||
Button btn = new Button(getContext());
|
Button btn = new Button(getContext());
|
||||||
btn.setText("Save");
|
btn.setText("Save");
|
||||||
btn.setTextSize(18);
|
btn.setTextSize(18);
|
||||||
@@ -222,11 +272,10 @@ public class TBAView extends ScrollView {
|
|||||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
));
|
));
|
||||||
// addTableText(tr, "test");
|
Table.addView(btn);
|
||||||
tr.addView(btn);
|
|
||||||
Table.addView(tr);
|
|
||||||
|
|
||||||
tr = new TableRow(getContext());
|
|
||||||
|
TableRow tr = new TableRow(getContext());
|
||||||
addTableText(tr, "#");
|
addTableText(tr, "#");
|
||||||
addTableText(tr, "Red-1");
|
addTableText(tr, "Red-1");
|
||||||
addTableText(tr, "Red-2");
|
addTableText(tr, "Red-2");
|
||||||
@@ -237,7 +286,7 @@ public class TBAView extends ScrollView {
|
|||||||
Table.addView(tr);
|
Table.addView(tr);
|
||||||
|
|
||||||
|
|
||||||
data = JSONUtil.sort(data, new Comparator(){
|
final JSONArray sortedMatchData = JSONUtil.sort(matchData, new Comparator(){
|
||||||
public int compare(Object a, Object b){
|
public int compare(Object a, Object b){
|
||||||
JSONObject ja = (JSONObject)a;
|
JSONObject ja = (JSONObject)a;
|
||||||
JSONObject jb = (JSONObject)b;
|
JSONObject jb = (JSONObject)b;
|
||||||
@@ -250,11 +299,12 @@ public class TBAView extends ScrollView {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
final ArrayList<frcMatch> matchesOBJ = new ArrayList<frcMatch>();
|
||||||
boolean toggle = false;
|
boolean toggle = false;
|
||||||
int matchCount = 1;
|
int matchCount = 1;
|
||||||
|
|
||||||
for(int a=0;a<data.length();a++){
|
for(int a=0;a<sortedMatchData.length();a++){
|
||||||
final JSONObject match = data.getJSONObject(a);
|
final JSONObject match = sortedMatchData.getJSONObject(a);
|
||||||
|
|
||||||
if(!match.getString("comp_level").equals("qm")){
|
if(!match.getString("comp_level").equals("qm")){
|
||||||
continue;
|
continue;
|
||||||
@@ -273,6 +323,9 @@ public class TBAView extends ScrollView {
|
|||||||
addTableText(tr, String.valueOf(matchCount));
|
addTableText(tr, String.valueOf(matchCount));
|
||||||
// addTableText(tr, match.getString("key"));
|
// addTableText(tr, match.getString("key"));
|
||||||
|
|
||||||
|
int[] blueKeys = new int[3];
|
||||||
|
int[] redKeys = new int[3];
|
||||||
|
|
||||||
for(int b=0;b<6;b++){
|
for(int b=0;b<6;b++){
|
||||||
TextView text = new TextView(getContext());
|
TextView text = new TextView(getContext());
|
||||||
text.setTextSize(18);
|
text.setTextSize(18);
|
||||||
@@ -280,24 +333,80 @@ public class TBAView extends ScrollView {
|
|||||||
tr.addView(text);
|
tr.addView(text);
|
||||||
|
|
||||||
if(b < 3){
|
if(b < 3){
|
||||||
text.setText(redAlliance.getString(b).substring(3));
|
String str = redAlliance.getString(b).substring(3);
|
||||||
|
redKeys[b] = (int)Integer.parseInt(str);
|
||||||
|
text.setText(str);
|
||||||
text.setBackgroundColor(0x50ff0000);
|
text.setBackgroundColor(0x50ff0000);
|
||||||
}else{
|
}else{
|
||||||
text.setText(blueAlliance.getString(b-3).substring(3));
|
String str = blueAlliance.getString(b-3).substring(3);
|
||||||
|
blueKeys[b-3] = (int)Integer.parseInt(str);
|
||||||
|
text.setText(str);
|
||||||
text.setBackgroundColor(0x500000ff);
|
text.setBackgroundColor(0x500000ff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Table.addView(tr);
|
Table.addView(tr);
|
||||||
|
|
||||||
|
frcMatch matchOBJ = new frcMatch();
|
||||||
|
matchOBJ.matchIndex = matchCount;
|
||||||
|
matchOBJ.blueAlliance = blueKeys;
|
||||||
|
matchOBJ.redAlliance = redKeys;
|
||||||
|
matchesOBJ.add(matchOBJ);
|
||||||
|
|
||||||
matchCount += 1;
|
matchCount += 1;
|
||||||
toggle = !toggle;
|
toggle = !toggle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btn.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if(saveData(matchesOBJ, teamData, eventData)){
|
||||||
|
alert("Info", "Saved!");
|
||||||
|
}else{
|
||||||
|
alert("Error", "Error saving files.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}catch (JSONException j){
|
}catch (JSONException j){
|
||||||
|
j.printStackTrace();
|
||||||
alert("Error", "Invalid JSON");
|
alert("Error", "Invalid JSON");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean saveData(ArrayList<frcMatch> matchData, JSONArray teamData, JSONObject eventData){
|
||||||
|
try {
|
||||||
|
final String matchKey = eventData.getString("key");
|
||||||
|
String matchName = eventData.getString("short_name");
|
||||||
|
|
||||||
|
// Sometimes, a short name is not present on TBA Events
|
||||||
|
if(matchName.isEmpty()){
|
||||||
|
matchName = eventData.getString("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList<frcTeam> teams = new ArrayList<frcTeam>();
|
||||||
|
for(int i=0;i<teamData.length();i++){
|
||||||
|
frcTeam teamObj = new frcTeam();
|
||||||
|
JSONObject team = teamData.getJSONObject(i);
|
||||||
|
|
||||||
|
teamObj.teamNumber = team.getInt("team_number");
|
||||||
|
teamObj.teamName = team.getString("nickname");
|
||||||
|
teamObj.city = team.getString("city");
|
||||||
|
teamObj.stateOrProv = team.getString("state_prov");
|
||||||
|
teamObj.school = team.getString("school_name");
|
||||||
|
teamObj.country = team.getString("country");
|
||||||
|
teamObj.startingYear = team.getInt("rookie_year");
|
||||||
|
|
||||||
|
teams.add(teamObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileEditor.setMatches(getContext(), matchKey, matchName, matchData) &&
|
||||||
|
fileEditor.setTeams(getContext(), matchKey, teams);
|
||||||
|
}catch (JSONException j){
|
||||||
|
j.printStackTrace();
|
||||||
|
alert("Error", "Invalid JSON");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,10 +1,12 @@
|
|||||||
package com.astatin3.scoutingapp2025.ui.transfer;
|
package com.astatin3.scoutingapp2025.ui.transfer;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -13,6 +15,7 @@ import androidx.constraintlayout.widget.ConstraintLayout;
|
|||||||
|
|
||||||
import com.astatin3.scoutingapp2025.R;
|
import com.astatin3.scoutingapp2025.R;
|
||||||
import com.astatin3.scoutingapp2025.databinding.FragmentTransferBinding;
|
import com.astatin3.scoutingapp2025.databinding.FragmentTransferBinding;
|
||||||
|
import com.astatin3.scoutingapp2025.fileEditor;
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
import com.google.zxing.EncodeHintType;
|
import com.google.zxing.EncodeHintType;
|
||||||
import com.google.zxing.WriterException;
|
import com.google.zxing.WriterException;
|
||||||
@@ -20,7 +23,11 @@ import com.google.zxing.common.BitMatrix;
|
|||||||
import com.google.zxing.qrcode.QRCodeWriter;
|
import com.google.zxing.qrcode.QRCodeWriter;
|
||||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -51,6 +58,7 @@ public class generatorView extends ConstraintLayout {
|
|||||||
private int qrCount = 0;
|
private int qrCount = 0;
|
||||||
|
|
||||||
private ArrayList<Bitmap> qrBitmaps;
|
private ArrayList<Bitmap> qrBitmaps;
|
||||||
|
|
||||||
public generatorView(Context context) {
|
public generatorView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
@@ -90,17 +98,44 @@ public class generatorView extends ConstraintLayout {
|
|||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(FragmentTransferBinding binding, String data){
|
public void start(FragmentTransferBinding binding, String inputData){
|
||||||
qrImage = binding.qrImage;
|
qrImage = binding.qrImage;
|
||||||
qrSpeedSlider = binding.qrSpeedSlider;
|
qrSpeedSlider = binding.qrSpeedSlider;
|
||||||
qrSizeSlider = binding.qrSizeSlider;
|
qrSizeSlider = binding.qrSizeSlider;
|
||||||
qrIndexN = binding.qrIndexN;
|
qrIndexN = binding.qrIndexN;
|
||||||
qrIndexD = binding.qrIndexD;
|
qrIndexD = binding.qrIndexD;
|
||||||
|
|
||||||
sendData(data);
|
String compiledData = null;
|
||||||
|
try {
|
||||||
|
byte[] tempData = fileEditor.compress(inputData.getBytes("UTF-8"));
|
||||||
|
compiledData = new String(tempData, "UTF-8");
|
||||||
|
alert(""+tempData.length, fileEditor.binaryVisualize(tempData));
|
||||||
|
Log.i("Info", fileEditor.binaryVisualize(tempData));
|
||||||
|
|
||||||
|
}catch (UnsupportedEncodingException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(compiledData == null || inputData.length() < compiledData.length()){
|
||||||
|
sendData(inputData);
|
||||||
|
}else{
|
||||||
|
sendData(compiledData);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void alert(String title, String content) {
|
||||||
|
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
|
||||||
|
alert.setMessage(content);
|
||||||
|
alert.setTitle(title);
|
||||||
|
alert.setPositiveButton("OK", null);
|
||||||
|
alert.setCancelable(true);
|
||||||
|
alert.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendData(String data){
|
private void sendData(String data){
|
||||||
|
|
||||||
minQrSize = Math.round(data.length()/maxQrCount);
|
minQrSize = Math.round(data.length()/maxQrCount);
|
||||||
|
|
||||||
qrSizeSlider.setMax(maxQrSize-minQrSize);
|
qrSizeSlider.setMax(maxQrSize-minQrSize);
|
||||||
@@ -139,15 +174,19 @@ public class generatorView extends ConstraintLayout {
|
|||||||
qrSpeedSlider.setProgress(defaultQrDelay+5);
|
qrSpeedSlider.setProgress(defaultQrDelay+5);
|
||||||
|
|
||||||
qrBitmaps = new ArrayList<Bitmap>();
|
qrBitmaps = new ArrayList<Bitmap>();
|
||||||
for(int i=0;i<=(data.length()/qrSize);i++){
|
for(int i=0;i<=((data.length()+1)/qrSize);i++){
|
||||||
final int start = i*qrSize;
|
final int start = i*qrSize;
|
||||||
int end = (i+1)*qrSize;
|
int end = (i+1)*qrSize;
|
||||||
if(end > data.length()){
|
if(end >= data.length()){
|
||||||
end = data.length()-1;
|
end = data.length();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
// alert("test", ""+Math.ceil((double)data.length()/(double)qrSize));
|
||||||
qrBitmaps.add(generateQrCode(
|
qrBitmaps.add(generateQrCode(
|
||||||
data.substring(start, end)
|
String.valueOf(fileEditor.toChar(fileEditor.internalDataVersion)) +
|
||||||
|
String.valueOf(fileEditor.toChar(i)) +
|
||||||
|
String.valueOf(fileEditor.toChar(qrCount-1)) +
|
||||||
|
data.substring(start, end)
|
||||||
));
|
));
|
||||||
}catch (WriterException e){
|
}catch (WriterException e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -173,6 +212,7 @@ public class generatorView extends ConstraintLayout {
|
|||||||
this.qrIndex = this.qrCount-1;
|
this.qrIndex = this.qrCount-1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qrIndexN.setText(String.valueOf(qrIndex+1));
|
qrIndexN.setText(String.valueOf(qrIndex+1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,60 @@
|
|||||||
package com.astatin3.scoutingapp2025.ui.transfer;
|
package com.astatin3.scoutingapp2025.ui.transfer;
|
||||||
|
|
||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.SurfaceView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
|
|
||||||
import com.astatin3.scoutingapp2025.databinding.FragmentTransferBinding;
|
import com.astatin3.scoutingapp2025.databinding.FragmentTransferBinding;
|
||||||
|
import com.astatin3.scoutingapp2025.fileEditor;
|
||||||
import com.astatin3.scoutingapp2025.qrPointsOverlayView;
|
import com.astatin3.scoutingapp2025.qrPointsOverlayView;
|
||||||
import com.dlazaro66.qrcodereaderview.QRCodeReaderView;
|
import com.dlazaro66.qrcodereaderview.QRCodeReaderView;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.zip.DataFormatException;
|
||||||
|
|
||||||
public class scannerView extends ConstraintLayout {
|
public class scannerView extends ConstraintLayout {
|
||||||
|
public static class fixedQRCodeReaderView extends QRCodeReaderView {
|
||||||
|
public fixedQRCodeReaderView(Context context) {
|
||||||
|
super(context, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private QRCodeReaderView qrCodeReaderView;
|
private QRCodeReaderView qrCodeReaderView;
|
||||||
private qrPointsOverlayView pointsOverlayView;
|
private qrPointsOverlayView pointsOverlayView;
|
||||||
|
private String[] qrDataArr;
|
||||||
|
|
||||||
private class codeReadListener implements QRCodeReaderView.OnQRCodeReadListener {
|
private class codeReadListener implements QRCodeReaderView.OnQRCodeReadListener {
|
||||||
@Override
|
@Override
|
||||||
public void onQRCodeRead(String text, PointF[] points) {
|
public void onQRCodeRead(String text, PointF[] points) {
|
||||||
pointsOverlayView.setPoints(points);
|
pointsOverlayView.setPoints(points);
|
||||||
|
|
||||||
|
compileData(
|
||||||
|
fileEditor.fromChar(text.charAt(0)),
|
||||||
|
fileEditor.fromChar(text.charAt(1)),
|
||||||
|
(fileEditor.fromChar(text.charAt(2))+1),
|
||||||
|
text.substring(3)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void alert(String title, String content) {
|
||||||
|
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
|
||||||
|
alert.setMessage(content);
|
||||||
|
alert.setTitle(title);
|
||||||
|
alert.setPositiveButton("OK", null);
|
||||||
|
alert.setCancelable(true);
|
||||||
|
alert.create().show();
|
||||||
|
}
|
||||||
|
|
||||||
public scannerView(Context context) {
|
public scannerView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
@@ -63,4 +95,46 @@ public class scannerView extends ConstraintLayout {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void compileData(int dataVersion, int qrIndex, int qrCount, String qrData){
|
||||||
|
if(dataVersion != fileEditor.internalDataVersion){
|
||||||
|
alert("Error", "Incorrect data version");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(qrDataArr == null || qrDataArr.length != qrCount){
|
||||||
|
qrDataArr = new String[qrCount];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(qrDataArr[qrIndex] == null) {
|
||||||
|
qrDataArr[qrIndex] = qrData;
|
||||||
|
alert((qrIndex+1)+"/"+qrCount, qrData);
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
for(int i =0;i<qrCount;i++){
|
||||||
|
if(qrDataArr[i] != null){
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count >= qrCount){
|
||||||
|
|
||||||
|
// I guess String.join does not like non-ascii text
|
||||||
|
String compiledData = "";
|
||||||
|
for(int i=0;i<qrCount;i++){
|
||||||
|
compiledData += qrDataArr[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
byte[] compiledBytes = compiledData.getBytes(StandardCharsets.ISO_8859_1);
|
||||||
|
// alert("completed", ""+fileEditor.decompress(compiledBytes));
|
||||||
|
alert(""+compiledBytes.length, fileEditor.binaryVisualize(compiledBytes));
|
||||||
|
Log.i("Info", fileEditor.binaryVisualize(compiledBytes));
|
||||||
|
}catch (Exception e){
|
||||||
|
// alert("completed", compiledData);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user