diff --git a/app/src/main/java/com/ridgebotics/ridgescout/scoutingData/fields.java b/app/src/main/java/com/ridgebotics/ridgescout/scoutingData/fields.java index 366f72b..8a37bd6 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/scoutingData/fields.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/scoutingData/fields.java @@ -14,6 +14,7 @@ import com.ridgebotics.ridgescout.utility.BuiltByteParser; import com.ridgebotics.ridgescout.utility.ByteBuilder; import java.util.ArrayList; +import java.util.UUID; public class fields { // public static ScoutingVersion sv = new ScoutingVersion(); @@ -21,66 +22,70 @@ public class fields { public static final String matchFieldsFilename = "matches.fields"; public static final String pitsFieldsFilename = "pits.fields"; + private static String uuid(){ + return UUID.randomUUID().toString(); + } + public static final inputType[][] default_match_fields = new inputType[][] { { - new fieldposType("Auto start pos", "Where does the robot start its auto?", new int[]{0,0}), + new fieldposType(uuid(),"Auto start pos", "Where does the robot start its auto?", new int[]{0,0}), - new tallyType("Auto L4 Coral", "How many coral did this robot score in L4 during auto?", 0), - new tallyType("Auto L3 Coral", "How many coral did this robot score in L3 during auto?", 0), - new tallyType("Auto L2 Coral", "How many coral did this robot score in L2 during auto?", 0), - new tallyType("Auto L1/Trough Coral", "How many coral did this robot score in L1 during auto?", 0), - new tallyType("Auto Processor Algae", "How many algae did this robot score in the Barge during auto?", 0), - new tallyType("Auto Barge Algae", "How many algae did this robot score in the Barge during auto?", 0), + new tallyType(uuid(),"Auto L4 Coral", "How many coral did this robot score in L4 during auto?", 0), + new tallyType(uuid(),"Auto L3 Coral", "How many coral did this robot score in L3 during auto?", 0), + new tallyType(uuid(),"Auto L2 Coral", "How many coral did this robot score in L2 during auto?", 0), + new tallyType(uuid(),"Auto L1/Trough Coral", "How many coral did this robot score in L1 during auto?", 0), + new tallyType(uuid(),"Auto Processor Algae", "How many algae did this robot score in the Barge during auto?", 0), + new tallyType(uuid(),"Auto Barge Algae", "How many algae did this robot score in the Barge during auto?", 0), - new dropdownType("Auto Quality", "How did the robot drive during auto?", new String[]{"Smooth", "Jittery"}, 0), - new textType("Auto Comments", "Anything interesting about auto", ""), + new dropdownType(uuid(),"Auto Quality", "How did the robot drive during auto?", new String[]{"Smooth", "Jittery"}, 0), + new textType(uuid(),"Auto Comments", "Anything interesting about auto", ""), - new tallyType("Teleop L4 Coral", "How many coral did this robot score in L4 during auto?", 0), - new tallyType("Teleop L3 Coral", "How many coral did this robot score in L3 during auto?", 0), - new tallyType("Teleop L2 Coral", "How many coral did this robot score in L2 during auto?", 0), - new tallyType("Teleop L1 Coral", "How many coral did this robot score in L1 during auto?", 0), - new tallyType("Teleop Processor Algae", "How many algae did this robot score in the Barge during auto?", 0), - new tallyType("Teleop Barge Algae", "How many algae did this robot score in the Barge during auto?", 0), + new tallyType(uuid(),"Teleop L4 Coral", "How many coral did this robot score in L4 during auto?", 0), + new tallyType(uuid(),"Teleop L3 Coral", "How many coral did this robot score in L3 during auto?", 0), + new tallyType(uuid(),"Teleop L2 Coral", "How many coral did this robot score in L2 during auto?", 0), + new tallyType(uuid(),"Teleop L1 Coral", "How many coral did this robot score in L1 during auto?", 0), + new tallyType(uuid(),"Teleop Processor Algae", "How many algae did this robot score in the Barge during auto?", 0), + new tallyType(uuid(),"Teleop Barge Algae", "How many algae did this robot score in the Barge during auto?", 0), - new checkboxType("Upper Algae Removal", "Did the robot remove upper Algae?", 0), - new checkboxType("Lower Algae Removal", "Did the robot remove lower Algae?", 0), + new checkboxType(uuid(),"Upper Algae Removal", "Did the robot remove upper Algae?", 0), + new checkboxType(uuid(),"Lower Algae Removal", "Did the robot remove lower Algae?", 0), - new dropdownType("Teleop Quality", "How did the robot drive during Teleop?", new String[]{"Smooth", "Jittery"}, 0), - new textType("Teleop Comments", "Anything interesting about Teleop", ""), + new dropdownType(uuid(),"Teleop Quality", "How did the robot drive during Teleop?", new String[]{"Smooth", "Jittery"}, 0), + new textType(uuid(),"Teleop Comments", "Anything interesting about Teleop", ""), - new dropdownType("Climb State", "What was the final condition of the robot?", new String[]{"Nothing", "Continued Cycling", "Park", "Attempted Shallow", "Shallow", "Attempted Deep", "Deep"}, 0), + new dropdownType(uuid(),"Climb State", "What was the final condition of the robot?", new String[]{"Nothing", "Continued Cycling", "Park", "Attempted Shallow", "Shallow", "Attempted Deep", "Deep"}, 0), - new dropdownType("Robot Condition", "Was anything broken?", new String[]{"Everything was working", "Something was maybe broken", "Something was broken", "Robot was disabled for part of the match", "Missing robot"}, 0), + new dropdownType(uuid(),"Robot Condition", "Was anything broken?", new String[]{"Everything was working", "Something was maybe broken", "Something was broken", "Robot was disabled for part of the match", "Missing robot"}, 0), - new textType("Other Comments", "Any other comments you have", "") + new textType(uuid(),"Other Comments", "Any other comments you have", "") } }; public static final inputType[][] default_pit_fields = new inputType[][] { { - new dropdownType("Drivetrain type", "What type of drivetrain does this team have?", new String[]{"Swerve Drive", "Tank Drive (Differential)", "Other, Info in comments"}, 0), - new dropdownType("Intake type", "What type of intake does this team have?", new String[]{"Ground only", "Player Station only", "Both", "Other, Info in comments"}, 0), - new dropdownType("Intake Consistency", "How consistent is the robot at intakeing?", new String[]{"Does not work", "Worked a few times during testing", "Works most of the time", "Fails sometimes", "Never fails"}, 0), + new dropdownType(uuid(),"Drivetrain type", "What type of drivetrain does this team have?", new String[]{"Swerve Drive", "Tank Drive (Differential)", "Other, Info in comments"}, 0), + new dropdownType(uuid(),"Intake type", "What type of intake does this team have?", new String[]{"Ground only", "Player Station only", "Both", "Other, Info in comments"}, 0), + new dropdownType(uuid(),"Intake Consistency", "How consistent is the robot at intakeing?", new String[]{"Does not work", "Worked a few times during testing", "Works most of the time", "Fails sometimes", "Never fails"}, 0), - new dropdownType("Score Area", "What does this robot score?", new String[]{"Only Algae", "Mostly Algae", "Both", "Mostly Coral", "Only Coral"}, 0), + new dropdownType(uuid(),"Score Area", "What does this robot score?", new String[]{"Only Algae", "Mostly Algae", "Both", "Mostly Coral", "Only Coral"}, 0), - new checkboxType("L4 Scoring", "Will the robot score in Layer 4?", 0), - new checkboxType("L3 Scoring", "Will the robot score in Layer 3?", 0), - new checkboxType("L2 Scoring", "Will the robot score in Layer 3?", 0), - new checkboxType("L1/Trough Scoring", "Will the robot score in Layer 1?", 0), - new checkboxType("Processor Scoring", "Will the robot score in the Processor?", 0), - new checkboxType("Barge Scoring", "Will the robot score algae in the Barge?", 0), - new dropdownType("Scoring Consistency", "How consistent is the robot at Scoring?", new String[]{"Does not work", "Worked a few times during testing", "Works most of the time", "Fails sometimes", "Never fails"}, 0), + new checkboxType(uuid(),"L4 Scoring", "Will the robot score in Layer 4?", 0), + new checkboxType(uuid(),"L3 Scoring", "Will the robot score in Layer 3?", 0), + new checkboxType(uuid(),"L2 Scoring", "Will the robot score in Layer 3?", 0), + new checkboxType(uuid(),"L1/Trough Scoring", "Will the robot score in Layer 1?", 0), + new checkboxType(uuid(),"Processor Scoring", "Will the robot score in the Processor?", 0), + new checkboxType(uuid(),"Barge Scoring", "Will the robot score algae in the Barge?", 0), + new dropdownType(uuid(),"Scoring Consistency", "How consistent is the robot at Scoring?", new String[]{"Does not work", "Worked a few times during testing", "Works most of the time", "Fails sometimes", "Never fails"}, 0), - new textType("Auto Capability", "What autos does this team have?", ""), - new dropdownType("Auto Consistency", "How consistent is the robot at Auto?", new String[]{"Does not work", "Worked a few times during testing", "Works most of the time", "Fails sometimes", "Never fails"}, 0), + new textType(uuid(),"Auto Capability", "What autos does this team have?", ""), + new dropdownType(uuid(),"Auto Consistency", "How consistent is the robot at Auto?", new String[]{"Does not work", "Worked a few times during testing", "Works most of the time", "Fails sometimes", "Never fails"}, 0), - new dropdownType("Climb type", "What does the robot do to climb?", new String[]{"No Climb", "Only Shallow", "Only Deep", "Both Shallow and Deep"}, 0), - new dropdownType("Climb Consistency", "How consistent is the robot at climbing?", new String[]{"Does not work", "Worked a few times during testing", "Works most of the time", "Fails sometimes", "Never fails"}, 0), + new dropdownType(uuid(),"Climb type", "What does the robot do to climb?", new String[]{"No Climb", "Only Shallow", "Only Deep", "Both Shallow and Deep"}, 0), + new dropdownType(uuid(),"Climb Consistency", "How consistent is the robot at climbing?", new String[]{"Does not work", "Worked a few times during testing", "Works most of the time", "Fails sometimes", "Never fails"}, 0), - new textType("Cool Comments", "Is there anything cool about the robot?", ""), + new textType(uuid(),"Cool Comments", "Is there anything cool about the robot?", ""), - new textType("Comments", "Things go here", "Day 1:\n\nDay 2:\n\nDay 3:\n") + new textType(uuid(),"Comments", "Things go here", "Day 1:\n\nDay 2:\n\nDay 3:\n") } }; diff --git a/app/src/main/java/com/ridgebotics/ridgescout/types/input/checkboxType.java b/app/src/main/java/com/ridgebotics/ridgescout/types/input/checkboxType.java index 4dac5c1..01d1343 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/types/input/checkboxType.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/types/input/checkboxType.java @@ -41,26 +41,18 @@ public class checkboxType extends inputType { public Object get_fallback_value(){return 0;} public checkboxType(){}; public String get_type_name(){return "Checkbox";} - public checkboxType(String name, String description, int isChecked){ - super(name, description); + public checkboxType(String UUID, String name, String description, int isChecked){ + super(UUID, name, description); this.default_value = isChecked; } - public byte[] encode() throws ByteBuilder.buildingException { - ByteBuilder bb = new ByteBuilder(); - bb.addString(name); - bb.addString(description); + public void encodeData(ByteBuilder bb) throws ByteBuilder.buildingException { bb.addInt((int)default_value); - return bb.build(); } - public void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption { - BuiltByteParser bbp = new BuiltByteParser(bytes); - ArrayList objects = bbp.parse(); - name = (String) objects.get(0).get(); - description = (String) objects.get(1).get(); - default_value = objects.get(2).get(); + public void decodeData(ArrayList objects) { + default_value = objects.get(0).get(); } // public PowerSpinnerView dropdown = null; diff --git a/app/src/main/java/com/ridgebotics/ridgescout/types/input/dropdownType.java b/app/src/main/java/com/ridgebotics/ridgescout/types/input/dropdownType.java index 15fe0d3..cfb9f38 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/types/input/dropdownType.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/types/input/dropdownType.java @@ -42,29 +42,20 @@ public class dropdownType extends inputType { public Object get_fallback_value(){return 0;} public dropdownType(){}; public String get_type_name(){return "Dropdown";} - public dropdownType(String name, String description, String[] text_options, int defaultSelIndex){ - super(name, description); + public dropdownType(String UUID, String name, String description, String[] text_options, int defaultSelIndex){ + super(UUID, name, description); this.text_options = text_options; this.default_value = defaultSelIndex; } - public byte[] encode() throws ByteBuilder.buildingException { - ByteBuilder bb = new ByteBuilder(); - bb.addString(name); - bb.addString(description); + public void encodeData(ByteBuilder bb) throws ByteBuilder.buildingException { bb.addInt((int)default_value); bb.addStringArray(text_options); - return bb.build(); } - public void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption { - BuiltByteParser bbp = new BuiltByteParser(bytes); - ArrayList objects = bbp.parse(); - - name = (String) objects.get(0).get(); - description = (String) objects.get(1).get(); - default_value = objects.get(2).get(); - text_options = (String[]) objects.get(3).get(); + public void decodeData(ArrayList objects) { + default_value = objects.get(0).get(); + text_options = (String[]) objects.get(1).get(); } public CustomSpinnerView dropdown = null; diff --git a/app/src/main/java/com/ridgebotics/ridgescout/types/input/fieldposType.java b/app/src/main/java/com/ridgebotics/ridgescout/types/input/fieldposType.java index 61d2b06..1d1c559 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/types/input/fieldposType.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/types/input/fieldposType.java @@ -40,8 +40,8 @@ public class fieldposType extends inputType { public Object get_fallback_value(){return 0;} public fieldposType(){} public String get_type_name(){return "Field Pos";} - public fieldposType(String name, String description, int[] default_value){ - super(name, description); + public fieldposType(String UUID, String name, String description, int[] default_value){ + super(UUID, name, description); this.default_value = default_value; } @@ -49,21 +49,12 @@ public class fieldposType extends inputType { - public byte[] encode() throws ByteBuilder.buildingException { - ByteBuilder bb = new ByteBuilder(); - bb.addString(name); - bb.addString(description); + public void encodeData(ByteBuilder bb) throws ByteBuilder.buildingException { bb.addIntArray((int[]) default_value); - return bb.build(); } - public void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption { - BuiltByteParser bbp = new BuiltByteParser(bytes); - ArrayList objects = bbp.parse(); - - name = (String) objects.get(0).get(); - description = (String) objects.get(1).get(); - default_value = objects.get(2).get(); + public void decodeData(ArrayList objects) { + default_value = objects.get(0).get(); } diff --git a/app/src/main/java/com/ridgebotics/ridgescout/types/input/inputType.java b/app/src/main/java/com/ridgebotics/ridgescout/types/input/inputType.java index 69b7269..8615482 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/types/input/inputType.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/types/input/inputType.java @@ -9,6 +9,7 @@ import com.ridgebotics.ridgescout.types.data.dataType; import com.ridgebotics.ridgescout.utility.BuiltByteParser; import com.ridgebotics.ridgescout.utility.ByteBuilder; +import java.util.ArrayList; import java.util.List; import java.util.function.Function; @@ -30,6 +31,7 @@ public abstract class inputType { CHECKBOX, FIELDPOS } + public String UUID; public String name; public String description; public Object default_value; @@ -38,15 +40,41 @@ public abstract class inputType { public abstract Object get_fallback_value(); public abstract int get_byte_id(); public inputType(){} - public inputType(String name, String description){ + public inputType(String UUID, String name, String description){ + this.UUID = UUID; this.name = name; this.description = description; } public abstract String get_type_name(); - public abstract byte[] encode() throws ByteBuilder.buildingException; - public abstract void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption; + public byte[] encode() throws ByteBuilder.buildingException { + ByteBuilder bb = new ByteBuilder(); + bb.addString(UUID); + bb.addString(name); + bb.addString(description); + + encodeData(bb); + + return bb.build(); + } + + + public abstract void encodeData(ByteBuilder byteBuilder) throws ByteBuilder.buildingException; + public void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption { + BuiltByteParser bbp = new BuiltByteParser(bytes); + ArrayList objects = bbp.parse(); + + UUID = (String) objects.remove(0).get(); + name = (String) objects.remove(0).get(); + + description = (String) objects.remove(0).get(); + + decodeData(objects); + } + + + public abstract void decodeData(ArrayList objects); // public abstract dataType[] getConfig(); // public abstract void setConfig(dataType[] config); diff --git a/app/src/main/java/com/ridgebotics/ridgescout/types/input/numberType.java b/app/src/main/java/com/ridgebotics/ridgescout/types/input/numberType.java index 66e7fe1..67c249a 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/types/input/numberType.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/types/input/numberType.java @@ -36,8 +36,8 @@ public class numberType extends inputType { public Object get_fallback_value(){return 0;} public numberType(){} public String get_type_name(){return "Number";} - public numberType(String name, String description, int default_value){ - super(name, description); + public numberType(String UUID, String name, String description, int default_value){ + super(UUID, name, description); this.default_value = default_value; } @@ -45,20 +45,11 @@ public class numberType extends inputType { - public byte[] encode() throws ByteBuilder.buildingException { - ByteBuilder bb = new ByteBuilder(); - bb.addString(name); - bb.addString(description); + public void encodeData(ByteBuilder bb) throws ByteBuilder.buildingException { bb.addInt((int)default_value); - return bb.build(); } - public void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption { - BuiltByteParser bbp = new BuiltByteParser(bytes); - ArrayList objects = bbp.parse(); - - name = (String) objects.get(0).get(); - description = (String) objects.get(1).get(); - default_value = objects.get(2).get(); + public void decodeData(ArrayList objects) { + default_value = objects.get(0).get(); } diff --git a/app/src/main/java/com/ridgebotics/ridgescout/types/input/sliderType.java b/app/src/main/java/com/ridgebotics/ridgescout/types/input/sliderType.java index aac2b0f..9bb2443 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/types/input/sliderType.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/types/input/sliderType.java @@ -35,8 +35,8 @@ public class sliderType extends inputType { public Object get_fallback_value(){return 0;} public sliderType(){}; public String get_type_name(){return "Slider";} - public sliderType(String name, String description, int defaultValue, int min, int max){ - super(name, description); + public sliderType(String UUID, String name, String description, int defaultValue, int min, int max){ + super(UUID, name, description); this.default_value = defaultValue; this.min = min; this.max = max; @@ -45,24 +45,15 @@ public class sliderType extends inputType { - public byte[] encode() throws ByteBuilder.buildingException { - ByteBuilder bb = new ByteBuilder(); - bb.addString(name); - bb.addString(description); - bb.addInt((int)default_value); + public void encodeData(ByteBuilder bb) throws ByteBuilder.buildingException { + bb.addInt((int) default_value); bb.addInt(min); bb.addInt(max); - return bb.build(); } - public void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption { - BuiltByteParser bbp = new BuiltByteParser(bytes); - ArrayList objects = bbp.parse(); - - name = (String) objects.get(0).get(); - description = (String) objects.get(1).get(); - default_value = objects.get(2).get(); - min = (int) objects.get(3).get(); - max = (int) objects.get(4).get(); + public void decodeData(ArrayList objects) { + default_value = objects.get(0).get(); + min = (int) objects.get(1).get(); + max = (int) objects.get(2).get(); } diff --git a/app/src/main/java/com/ridgebotics/ridgescout/types/input/tallyType.java b/app/src/main/java/com/ridgebotics/ridgescout/types/input/tallyType.java index 71edbcd..254425c 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/types/input/tallyType.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/types/input/tallyType.java @@ -33,8 +33,8 @@ public class tallyType extends inputType { public Object get_fallback_value(){return 0;} public tallyType(){} public String get_type_name(){return "Tally";} - public tallyType(String name, String description, int default_value){ - super(name, description); + public tallyType(String UUID, String name, String description, int default_value){ + super(UUID, name, description); this.default_value = default_value; } @@ -42,20 +42,11 @@ public class tallyType extends inputType { - public byte[] encode() throws ByteBuilder.buildingException { - ByteBuilder bb = new ByteBuilder(); - bb.addString(name); - bb.addString(description); - bb.addInt((int)default_value); - return bb.build(); + public void encodeData(ByteBuilder bb) throws ByteBuilder.buildingException { + bb.addInt((int) default_value); } - public void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption { - BuiltByteParser bbp = new BuiltByteParser(bytes); - ArrayList objects = bbp.parse(); - - name = (String) objects.get(0).get(); - description = (String) objects.get(1).get(); - default_value = objects.get(2).get(); + public void decodeData(ArrayList objects) { + default_value = objects.get(0).get(); } diff --git a/app/src/main/java/com/ridgebotics/ridgescout/types/input/textType.java b/app/src/main/java/com/ridgebotics/ridgescout/types/input/textType.java index 6664d16..7811fca 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/types/input/textType.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/types/input/textType.java @@ -35,8 +35,8 @@ public class textType extends inputType { public dataType.valueTypes getValueType(){return dataType.valueTypes.STRING;} public Object get_fallback_value(){return "";} public textType(){} - public textType(String name, String description, String default_text){ - super(name, description); + public textType(String UUID, String name, String description, String default_text){ + super(UUID, name, description); this.default_value = default_text; } public String get_type_name(){return "Text";} @@ -47,20 +47,11 @@ public class textType extends inputType { - public byte[] encode() throws ByteBuilder.buildingException { - ByteBuilder bb = new ByteBuilder(); - bb.addString(name); - bb.addString(description); + public void encodeData(ByteBuilder bb) throws ByteBuilder.buildingException { bb.addString((String) default_value); - return bb.build(); } - public void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption { - BuiltByteParser bbp = new BuiltByteParser(bytes); - ArrayList objects = bbp.parse(); - - name = (String) objects.get(0).get(); - description = (String) objects.get(1).get(); - default_value = objects.get(2).get(); + public void decodeData(ArrayList objects) { + default_value = objects.get(0).get(); } diff --git a/app/src/main/java/com/ridgebotics/ridgescout/ui/FieldDisplay.java b/app/src/main/java/com/ridgebotics/ridgescout/ui/FieldDisplay.java new file mode 100644 index 0000000..54bd98a --- /dev/null +++ b/app/src/main/java/com/ridgebotics/ridgescout/ui/FieldDisplay.java @@ -0,0 +1,106 @@ +package com.ridgebotics.ridgescout.ui; + +import android.content.Context; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.Nullable; +import androidx.constraintlayout.widget.ConstraintLayout; + +import com.ridgebotics.ridgescout.R; +import com.ridgebotics.ridgescout.types.input.inputType; + +public class FieldDisplay extends ConstraintLayout { + public FieldDisplay(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + init(context); + } + + public FieldDisplay(Context context) { + super(context); + init(context); + } + + private inputType field; + + public Button editButton; + + private TextView titleText; + private TextView typeText; + +// private View fieldView; + private LinearLayout buttonBox; + private ConstraintLayout box; + private View coloredBackground; + + public void init(Context context) { + LayoutInflater.from(context).inflate(R.layout.view_field_display, this, true); + + box = findViewById(R.id.field_box); + coloredBackground = findViewById(R.id.field_background); + + titleText = findViewById(R.id.field_title); + typeText = findViewById(R.id.field_description); + + buttonBox = findViewById(R.id.buttons); + } + + public void setInputType(inputType field){ + this.field = field; + + titleText.setText(field.name); + typeText.setText(field.get_type_name()); + } + +// public void setField(View newView){ +// if(fieldView != null) +// box.removeView(fieldView); +// box.addView(newView); +// fieldView = newView; +// } + + +// public void fromTeam(frcTeam team){ +// setTeamNumber(team.teamNumber); +// setTeamName(team.teamName); +// +// if(team.bitmap != null) { +// setTeamLogo(team.bitmap); +// }else{ +// hideLogo(); +// } +// +// setColor(team.getTeamColor()); +// } + public void showButtons(){ + findViewById(R.id.buttons).setVisibility(View.VISIBLE); + } + + public void hideButtons(){ + findViewById(R.id.buttons).setVisibility(View.GONE); + } + + public void setColor(int color){ + Drawable drawable = box.getBackground(); + drawable.mutate(); + drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); + + float[] hsv = new float[3]; + Color.colorToHSV(color,hsv); + + coloredBackground.setBackgroundColor( + Color.HSVToColor(127, new float[]{ + hsv[0], + Math.min(hsv[1] - 0.25f, 0.75f), + Math.min(hsv[2] - 0.25f, 0.5f) + }) + ); + } +} diff --git a/app/src/main/java/com/ridgebotics/ridgescout/ui/settings/FieldsFragment.java b/app/src/main/java/com/ridgebotics/ridgescout/ui/settings/FieldsFragment.java index 22e1a09..0d66237 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/ui/settings/FieldsFragment.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/ui/settings/FieldsFragment.java @@ -24,6 +24,7 @@ import com.ridgebotics.ridgescout.MainActivity; import com.ridgebotics.ridgescout.R; import com.ridgebotics.ridgescout.databinding.FragmentSettingsFieldsBinding; import com.ridgebotics.ridgescout.scoutingData.fields; +import com.ridgebotics.ridgescout.types.data.dataType; import com.ridgebotics.ridgescout.types.input.checkboxType; import com.ridgebotics.ridgescout.types.input.dropdownType; import com.ridgebotics.ridgescout.types.input.fieldposType; @@ -33,11 +34,15 @@ import com.ridgebotics.ridgescout.types.input.sliderType; import com.ridgebotics.ridgescout.types.input.tallyType; import com.ridgebotics.ridgescout.types.input.textType; import com.ridgebotics.ridgescout.ui.CustomSpinnerView; +import com.ridgebotics.ridgescout.ui.FieldDisplay; import com.ridgebotics.ridgescout.utility.AlertManager; +import com.ridgebotics.ridgescout.utility.DataManager; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.function.Function; public class FieldsFragment extends Fragment { FragmentSettingsFieldsBinding binding; @@ -47,516 +52,596 @@ public class FieldsFragment extends Fragment { filename = tmpfilename; } - @SuppressLint("ClickableViewAccessibility") + private int index = -1; + + List values; + List views; + + + private static final int background_color = 0x5000ff00; + private static final int unfocused_background_color = 0x50118811; + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + binding = FragmentSettingsFieldsBinding.inflate(inflater, container, false); - binding.valueEditScrollview.setOnTouchListener((v, event) -> true); + binding.upButton.setEnabled(false); + binding.downButton.setEnabled(false); - binding.saveButton.setVisibility(View.GONE); - binding.cancelEditButton.setVisibility(View.GONE); - binding.editButton.setVisibility(View.GONE); - binding.upButton.setVisibility(View.GONE); - binding.addButton.setVisibility(View.GONE); - binding.downButton.setVisibility(View.GONE); - binding.deleteButton.setVisibility(View.GONE); + inputType[][] tmp_values = fields.load(filename); + if(tmp_values == null || tmp_values.length == 0) return binding.getRoot(); - binding.valueEditContainer.setVisibility(View.GONE); + values = new ArrayList(List.of(tmp_values[tmp_values.length-1])); + views = new ArrayList<>(); - load_field_menu(); + for(int i = 0; i < values.size(); i++){ + final FieldDisplay fd = new FieldDisplay(getContext()); + views.add(fd); - ((MainActivity) getActivity()).setOnBackPressed(() -> { - if(binding.saveButton.getVisibility() == View.GONE) return true; + fd.setInputType(values.get(i)); + fd.setColor(unfocused_background_color); - AlertDialog.Builder alert = new AlertDialog.Builder(getContext()); - alert.setTitle("Warning!"); - alert.setMessage("You have not saved your progress!"); - alert.setPositiveButton("Return", null); - alert.setNeutralButton("Quit without saving", (dialogInterface, i) -> { - binding.saveButton.setVisibility(View.GONE); - if(getActivity() != null) - getActivity().onBackPressed(); + final int fi = i; + fd.setOnClickListener(v -> { + index = views.indexOf(fd); + for(int a = 0; a < values.size(); a++) { + views.get(a).setColor(unfocused_background_color); + views.get(a).hideButtons(); + } + fd.setColor(background_color); + fd.showButtons(); + + binding.upButton.setEnabled(index > 0); + binding.downButton.setEnabled(index < views.size()-1); }); - alert.setCancelable(true); - alert.create().show(); - return false; + binding.fieldsArea.addView(fd); + } + + binding.upButton.setOnClickListener(v -> { + if(index <= 0) return; + Collections.swap(values, index, index-1); + Collections.swap(views, index, index-1); + index--; + updateRowOrder(); + }); + binding.downButton.setOnClickListener(v -> { + if(index >= values.size()-1) return; + Collections.swap(values, index, index+1); + Collections.swap(views, index, index+1); + index++; + updateRowOrder(); }); return binding.getRoot(); } - private static final int background_color = 0x5000ff00; - private static final int unfocused_background_color = 0x2000ff00; - - inputType[][] values; - - private void load_field_menu() { - - values = fields.load(filename); - - binding.fieldsArea.bringToFront(); - binding.fieldsArea.setStretchAllColumns(true); + private void updateRowOrder(){ binding.fieldsArea.removeAllViews(); - binding.fieldsArea.setReorderingEnabled(false); - - if(values == null) return; - - for(int i = 0; i < values.length; i++){ - - TableRow tr = new TableRow(getContext()); - TableLayout.LayoutParams rowParams = new TableLayout.LayoutParams( - FrameLayout.LayoutParams.WRAP_CONTENT, - FrameLayout.LayoutParams.WRAP_CONTENT - ); - - rowParams.setMargins(20,20,20,20); - tr.setLayoutParams(rowParams); - tr.setPadding(20,20,20,20); - - TextView tv = new TextView(getContext()); - tv.setText("v" + i); - tv.setTextSize(20); - tr.addView(tv); - - tv = new TextView(getContext()); - tv.setText(values[i].length + " Fields"); - tv.setTextSize(16); - tr.addView(tv); - - binding.fieldsArea.addView(tr); - - if(i == values.length-1) { - tr.setBackgroundColor(background_color); - int fi = i; - tr.setOnClickListener(v -> { - display_fields(values[fi]); - }); - }else{ - tr.setBackgroundColor(unfocused_background_color); - } + for(int i = 0; i < views.size(); i++){ + binding.fieldsArea.addView(views.get(i)); } - if(values.length > 1) { - binding.revertVersionButton.setVisibility(View.VISIBLE); - binding.revertVersionButton.setOnClickListener(v -> { - AlertDialog.Builder alert = new AlertDialog.Builder(getContext()); - alert.setTitle("Warning!"); - alert.setMessage("If there is any data set this version, it will be deleted!"); - alert.setPositiveButton("OK", (dialog, which) -> { - inputType[][] newArr = new inputType[values.length - 1][]; - System.arraycopy(values, 0, newArr, 0, values.length - 1); - if(fields.save(filename, newArr)) - AlertManager.toast("Saved"); - load_field_menu(); - }); - alert.setNegativeButton("Cancel", null); - alert.setCancelable(true); - alert.create().show(); - }); - } + binding.upButton.setEnabled(index > 0); + binding.downButton.setEnabled(index < views.size()-1); } - private void display_fields(inputType[] version_values) { - binding.fieldsArea.removeAllViews(); - binding.fieldsArea.setReorderingEnabled(false); - - binding.revertVersionButton.setVisibility(View.GONE); - - binding.saveButton.setVisibility(View.GONE); - binding.editButton.setVisibility(View.GONE); - binding.upButton.setVisibility(View.VISIBLE); - binding.addButton.setVisibility(View.VISIBLE); - binding.downButton.setVisibility(View.VISIBLE); - - updateUpDownAvailability(); - - binding.valueEditContainer.setVisibility(View.GONE); - - for(int i = 0; i < version_values.length; i++){ - addRow(version_values[i]); - } - selindex = -1; - - - binding.addButton.setOnClickListener(this::addField); - binding.saveButton.setOnClickListener(this::buttonfunc); - } - - // Make sure the user cannot move fields when they shouldn't - private void updateUpDownAvailability(){ - binding.upButton.setEnabled(selindex != -1 && selindex != 0); - binding.downButton.setEnabled(selindex != -1 && selindex != values[values.length-1].length-1); - } - - private void addRow(inputType field){ - TableRow tr = getTableRow(field); - - binding.fieldsArea.addView(tr); - - tr.setOnClickListener(v -> { - binding.editButton.setVisibility(View.VISIBLE); - trOnClick(values[values.length-1], tr); - updateUpDownAvailability(); - }); - - binding.upButton.setOnClickListener(v -> { - if(selindex != 0) { - binding.saveButton.setVisibility(View.VISIBLE); - binding.fieldsArea.updateRowOrder(selindex, selindex - 1); - selindex -= 1; - } - updateUpDownAvailability(); - }); - - binding.downButton.setOnClickListener(v -> { - if(selindex != values[values.length-1].length-1) { - binding.saveButton.setVisibility(View.VISIBLE); - binding.fieldsArea.updateRowOrder(selindex, selindex + 1); - selindex += 1; - } - updateUpDownAvailability(); - }); - - } - - private void buttonfunc(View v){ - AlertDialog.Builder alert = new AlertDialog.Builder(getContext()); - alert.setTitle("Warning!"); - alert.setMessage("Changing or removing some values will result in lost data!\nBut this will create a new field version, and you can revert at any time."); - alert.setPositiveButton("OK", (dialog, which) -> { - inputType[][] currentValues = fields.load(filename); - assert currentValues != null; - inputType[][] newValues = new inputType[currentValues.length+1][]; - System.arraycopy(currentValues, 0, newValues, 0, currentValues.length); - - newValues[newValues.length-1] = new inputType[values[values.length-1].length]; - - for(int i = 0; i < values[values.length-1].length; i++){ - newValues[newValues.length-1][i] = values[values.length-1][binding.fieldsArea.getReorderedIndexes().get(i)]; - } -// newValues[newValues.length-1] = values[values.length-1]; - - if(fields.save(filename, newValues)) - AlertManager.toast("Saved"); - - Navigation.findNavController((Activity) getContext(), R.id.nav_host_fragment_activity_main).navigate(R.id.action_navigation_data_fields_to_navigation_settings); - }); - alert.setNegativeButton("Cancel", null); - alert.setCancelable(true); - alert.create().show(); - } - - private int selindex = -1; - - private void trOnClick(inputType[] version_values, TableRow tr){ - selindex = -1; - for(int i = 0; i < binding.fieldsArea.getChildCount(); i++){ - View v = binding.fieldsArea.getChildAt(i); - - if(v.equals(tr)) { - tr.setBackgroundColor(background_color); - selindex = i; - } else - binding.fieldsArea.getChildAt(i).setBackgroundColor(unfocused_background_color); - } - - onFieldSelect(version_values[binding.fieldsArea.getReorderedIndexes().get(selindex)]); - } - - private void onFieldSelect(inputType field){ - //System.out.println(field.name); - - binding.editButton.setOnClickListener(v -> { - binding.editButton.setVisibility(View.GONE); - binding.addButton.setVisibility(View.GONE); - binding.upButton.setVisibility(View.GONE); - binding.downButton.setVisibility(View.GONE); - - binding.ValueEditTable.removeAllViews(); - binding.valueEditContainer.setVisibility(View.VISIBLE); - TextView tv = new TextView(getContext()); - - tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - tv.setText(field.name); - tv.setPadding(8,8,8,8); - tv.setTextSize(24); - - binding.ValueEditTable.addView(tv); - - final FieldEditorHelper fe = new FieldEditorHelper( - getContext(), - field, - binding.ValueEditTable - ); - - binding.saveButton.setVisibility(View.VISIBLE); - binding.saveButton.setOnClickListener(a -> { - System.out.println(fe.save()); - defaultVisibility(); - }); - - binding.cancelEditButton.setVisibility(View.VISIBLE); - binding.cancelEditButton.setOnClickListener(a -> { - defaultVisibility(); - }); - - binding.deleteButton.setVisibility(View.VISIBLE); - binding.deleteButton.setOnClickListener(a -> { - deleteField(field); - }); - }); - - } - - private void deleteField(inputType field){ - AlertDialog.Builder alert = new AlertDialog.Builder(getContext()); - alert.setTitle("Warning!"); - alert.setMessage("Removing a value will result in data being deleted in subsequent field versions!"); - alert.setNegativeButton("Cancel", null); - alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - defaultVisibility(); - - int oldindex = -1; - for(int i = 0; i < values[values.length - 1].length; i++){ - if(values[values.length - 1][i].equals(field)){ - oldindex = i; - break; - } - } - - if(oldindex != -1) { - System.out.println(Arrays.toString(values[values.length - 1])); - binding.fieldsArea.removeViewAt(selindex); - binding.fieldsArea.removeElement(oldindex); - values[values.length - 1] = removeElement(values[values.length - 1], oldindex); - selindex = -1; - AlertManager.toast("Removed!"); - binding.editButton.setVisibility(View.GONE); - System.out.println(Arrays.toString(values[values.length - 1])); - //System.out.println(values[values.length-1].length); - } - - } - }); - alert.setCancelable(true); - alert.create().show(); - } - - public inputType[] removeElement(inputType[] src, int i) { - inputType[] newArray = new inputType[src.length - 1]; - if (i > 0){ - System.arraycopy(src, 0, newArray, 0, i); - } - - if (newArray.length > i){ - System.arraycopy(src, i + 1, newArray, i, newArray.length - i); - } - - return newArray; - } - - - - - - - - - - - private void defaultVisibility() { - binding.editButton.setVisibility(View.VISIBLE); - binding.addButton.setVisibility(View.VISIBLE); - binding.upButton.setVisibility(View.VISIBLE); - binding.downButton.setVisibility(View.VISIBLE); - binding.ValueEditTable.removeAllViews(); - binding.valueEditContainer.setVisibility(View.GONE); - binding.cancelEditButton.setVisibility(View.GONE); - binding.deleteButton.setVisibility(View.GONE); - binding.saveButton.setOnClickListener(this::buttonfunc); - } - - - - - private void addField(View v) { - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setTitle("Title"); - - final EditText input = new EditText(getContext()); - input.setInputType(InputType.TYPE_CLASS_TEXT); - - builder.setView(input); - - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - } - }); - - builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String title = input.getText().toString(); - if(title.isEmpty() || title.isBlank()) { - AlertManager.addSimpleError("Title cannot be blank!"); - return; - } - addField_Part_2(title); - } - }); - - builder.show(); - } - - private void addField_Part_2(String title) { - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setTitle("Select Type"); - - final CustomSpinnerView dropdown = new CustomSpinnerView(getContext()); - List options = new ArrayList<>(); - - options.add("Slider"); - options.add("Text"); - options.add("Dropdown"); - options.add("Tally"); - options.add("Number"); - options.add("Checkbox"); - options.add("Field Position"); - - dropdown.setOptions(options, 0); - dropdown.setTitle("Type"); - - builder.setView(dropdown); - - builder.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel()); - builder.setPositiveButton("OK", (dialog, which) -> addField_Part_3(title, dropdown.getIndex())); - - builder.show(); - } - - private void addField_Part_3(String title, int typeIndex) { - switch (typeIndex){ - case 0: - sliderType slider = new sliderType(); - slider.name = title; - FieldEditorHelper.setSliderParams(slider, FieldEditorHelper.defaultSliderParams); - addField_Part_4(slider); - break; - case 1: - textType text = new textType(); - text.name = title; - FieldEditorHelper.setTextParams(text, FieldEditorHelper.defaultTextParams); - addField_Part_4(text); - break; - case 2: - dropdownType dropdown = new dropdownType(); - dropdown.name = title; - FieldEditorHelper.setDropdownParams(dropdown, FieldEditorHelper.defaultDropdownParams); - addField_Part_4(dropdown); - break; - case 3: - tallyType tally = new tallyType(); - tally.name = title; - FieldEditorHelper.setTallyParams(tally, FieldEditorHelper.defaultTallyParams); - addField_Part_4(tally); - break; - case 4: - numberType num = new numberType(); - num.name = title; - FieldEditorHelper.setNumberParams(num, FieldEditorHelper.defaultNumberParams); - addField_Part_4(num); - break; - case 5: - checkboxType cb = new checkboxType(); - cb.name = title; - FieldEditorHelper.setCheckboxParam(cb, FieldEditorHelper.defaultCheckboxParam); - addField_Part_4(cb); - break; - case 6: - fieldposType fp = new fieldposType(); - fp.name = title; - FieldEditorHelper.setFieldPosParam(fp, FieldEditorHelper.defaultFieldPosParam); - addField_Part_4(fp); - break; - - } - - } - private void addField_Part_4(inputType field) { - binding.editButton.setVisibility(View.GONE); - binding.addButton.setVisibility(View.GONE); - binding.upButton.setVisibility(View.GONE); - binding.downButton.setVisibility(View.GONE); - - binding.ValueEditTable.removeAllViews(); - binding.valueEditContainer.setVisibility(View.VISIBLE); - TextView tv = new TextView(getContext()); - - tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - tv.setText(field.name); - tv.setPadding(8,8,8,8); - tv.setTextSize(24); - - binding.ValueEditTable.addView(tv); - - final FieldEditorHelper fe = new FieldEditorHelper( - getContext(), - field, - binding.ValueEditTable - ); - - binding.saveButton.setVisibility(View.VISIBLE); - binding.saveButton.setOnClickListener(a -> { - inputType[] newValues = new inputType[values[values.length-1].length+1]; - System.arraycopy(values[values.length-1], 0, newValues, 0, values[values.length-1].length); - newValues[newValues.length-1] = field; - values[values.length-1] = newValues; - -// AlertManager.alert("Test", String.valueOf(binding.fieldsArea.getReorderedIndexes())); - - //TableRow tr = getTableRow(field); - //binding.fieldsArea.addView(tr); - addRow(field); - - System.out.println(fe.save()); - defaultVisibility(); - }); - - binding.cancelEditButton.setVisibility(View.VISIBLE); - binding.cancelEditButton.setOnClickListener(a -> { - defaultVisibility(); - }); - - } - - private @NonNull TableRow getTableRow(inputType field) { - TableRow tr = new TableRow(getContext()); - TableLayout.LayoutParams rowParams = new TableLayout.LayoutParams( - FrameLayout.LayoutParams.WRAP_CONTENT, - FrameLayout.LayoutParams.WRAP_CONTENT - ); - - rowParams.setMargins(20,20,20,20); - tr.setLayoutParams(rowParams); - tr.setPadding(20,20,20,20); - tr.setBackgroundColor(unfocused_background_color); - - TextView tv = new TextView(getContext()); - tv.setText(field.get_type_name()); - tv.setTextSize(12); - tr.addView(tv); - - tv = new TextView(getContext()); - tv.setText(field.name); - tv.setTextSize(20); - tr.addView(tv); - return tr; - } +// @SuppressLint("ClickableViewAccessibility") +// public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, +// @Nullable Bundle savedInstanceState) { +// binding = FragmentSettingsFieldsBinding.inflate(inflater, container, false); +// +// binding.valueEditScrollview.setOnTouchListener((v, event) -> true); +// +// binding.saveButton.setVisibility(View.GONE); +// binding.cancelEditButton.setVisibility(View.GONE); +// binding.editButton.setVisibility(View.GONE); +// binding.upButton.setVisibility(View.GONE); +// binding.addButton.setVisibility(View.GONE); +// binding.downButton.setVisibility(View.GONE); +// binding.deleteButton.setVisibility(View.GONE); +// +// binding.valueEditContainer.setVisibility(View.GONE); +// +// load_field_menu(); +// +// ((MainActivity) getActivity()).setOnBackPressed(() -> { +// if(binding.saveButton.getVisibility() == View.GONE) return true; +// +// AlertDialog.Builder alert = new AlertDialog.Builder(getContext()); +// alert.setTitle("Warning!"); +// alert.setMessage("You have not saved your progress!"); +// alert.setPositiveButton("Return", null); +// alert.setNeutralButton("Quit without saving", (dialogInterface, i) -> { +// binding.saveButton.setVisibility(View.GONE); +// if(getActivity() != null) +// getActivity().onBackPressed(); +// }); +// alert.setCancelable(true); +// +// alert.create().show(); +// +// return false; +// }); +// +// return binding.getRoot(); +// } + +// +// inputType[][] values; +// +// private void load_field_menu() { +// +// values = fields.load(filename); +// +// binding.fieldsArea.bringToFront(); +// binding.fieldsArea.setStretchAllColumns(true); +// binding.fieldsArea.removeAllViews(); +// binding.fieldsArea.setReorderingEnabled(false); +// +// if(values == null) return; +// +// for(int i = 0; i < values.length; i++){ +// +// TableRow tr = new TableRow(getContext()); +// TableLayout.LayoutParams rowParams = new TableLayout.LayoutParams( +// FrameLayout.LayoutParams.WRAP_CONTENT, +// FrameLayout.LayoutParams.WRAP_CONTENT +// ); +// +// rowParams.setMargins(20,20,20,20); +// tr.setLayoutParams(rowParams); +// tr.setPadding(20,20,20,20); +// +// TextView tv = new TextView(getContext()); +// tv.setText("v" + i); +// tv.setTextSize(20); +// tr.addView(tv); +// +// tv = new TextView(getContext()); +// tv.setText(values[i].length + " Fields"); +// tv.setTextSize(16); +// tr.addView(tv); +// +// binding.fieldsArea.addView(tr); +// +// if(i == values.length-1) { +// tr.setBackgroundColor(background_color); +// int fi = i; +// tr.setOnClickListener(v -> { +// display_fields(values[fi]); +// }); +// }else{ +// tr.setBackgroundColor(unfocused_background_color); +// } +// } +// +// if(values.length > 1) { +// binding.revertVersionButton.setVisibility(View.VISIBLE); +// binding.revertVersionButton.setOnClickListener(v -> { +// AlertDialog.Builder alert = new AlertDialog.Builder(getContext()); +// alert.setTitle("Warning!"); +// alert.setMessage("If there is any data set this version, it will be deleted!"); +// alert.setPositiveButton("OK", (dialog, which) -> { +// inputType[][] newArr = new inputType[values.length - 1][]; +// System.arraycopy(values, 0, newArr, 0, values.length - 1); +// if(fields.save(filename, newArr)) +// AlertManager.toast("Saved"); +// load_field_menu(); +// }); +// alert.setNegativeButton("Cancel", null); +// alert.setCancelable(true); +// alert.create().show(); +// }); +// } +// } +// +// private void display_fields(inputType[] version_values) { +// binding.fieldsArea.removeAllViews(); +// binding.fieldsArea.setReorderingEnabled(false); +// +// binding.revertVersionButton.setVisibility(View.GONE); +// +// binding.saveButton.setVisibility(View.GONE); +// binding.editButton.setVisibility(View.GONE); +// binding.upButton.setVisibility(View.VISIBLE); +// binding.addButton.setVisibility(View.VISIBLE); +// binding.downButton.setVisibility(View.VISIBLE); +// +// updateUpDownAvailability(); +// +// binding.valueEditContainer.setVisibility(View.GONE); +// +// for(int i = 0; i < version_values.length; i++){ +// addRow(version_values[i]); +// } +// selindex = -1; +// +// +// binding.addButton.setOnClickListener(this::addField); +// binding.saveButton.setOnClickListener(this::buttonfunc); +// } +// +// // Make sure the user cannot move fields when they shouldn't +// private void updateUpDownAvailability(){ +// binding.upButton.setEnabled(selindex != -1 && selindex != 0); +// binding.downButton.setEnabled(selindex != -1 && selindex != values[values.length-1].length-1); +// } +// +// private void addRow(inputType field){ +// View tr = getTableRow(field); +// +// binding.fieldsArea.addView(tr); +// +// tr.setOnClickListener(v -> { +// binding.editButton.setVisibility(View.VISIBLE); +// trOnClick(values[values.length-1], tr); +// updateUpDownAvailability(); +// }); +// +// binding.upButton.setOnClickListener(v -> { +// if(selindex != 0) { +// binding.saveButton.setVisibility(View.VISIBLE); +// binding.fieldsArea.updateRowOrder(selindex, selindex - 1); +// selindex -= 1; +// } +// updateUpDownAvailability(); +// }); +// +// binding.downButton.setOnClickListener(v -> { +// if(selindex != values[values.length-1].length-1) { +// binding.saveButton.setVisibility(View.VISIBLE); +// binding.fieldsArea.updateRowOrder(selindex, selindex + 1); +// selindex += 1; +// } +// updateUpDownAvailability(); +// }); +// +// } +// +// private void buttonfunc(View v){ +// AlertDialog.Builder alert = new AlertDialog.Builder(getContext()); +// alert.setTitle("Warning!"); +// alert.setMessage("Changing or removing some values will result in lost data!\nBut this will create a new field version, and you can revert at any time."); +// alert.setPositiveButton("OK", (dialog, which) -> { +// inputType[][] currentValues = fields.load(filename); +// assert currentValues != null; +// inputType[][] newValues = new inputType[currentValues.length+1][]; +// System.arraycopy(currentValues, 0, newValues, 0, currentValues.length); +// +// newValues[newValues.length-1] = new inputType[values[values.length-1].length]; +// +// for(int i = 0; i < values[values.length-1].length; i++){ +// newValues[newValues.length-1][i] = values[values.length-1][binding.fieldsArea.getReorderedIndexes().get(i)]; +// } +//// newValues[newValues.length-1] = values[values.length-1]; +// +// if(fields.save(filename, newValues)) +// AlertManager.toast("Saved"); +// +// Navigation.findNavController((Activity) getContext(), R.id.nav_host_fragment_activity_main).navigate(R.id.action_navigation_data_fields_to_navigation_settings); +// }); +// alert.setNegativeButton("Cancel", null); +// alert.setCancelable(true); +// alert.create().show(); +// } +// +// private int selindex = -1; +// +// private void trOnClick(inputType[] version_values, View tr){ +// selindex = -1; +// for(int i = 0; i < binding.fieldsArea.getChildCount(); i++){ +// View v = binding.fieldsArea.getChildAt(i); +// +// if(v.equals(tr)) { +// tr.setBackgroundColor(background_color); +// selindex = i; +// } else +// binding.fieldsArea.getChildAt(i).setBackgroundColor(unfocused_background_color); +// } +// +// onFieldSelect(version_values[binding.fieldsArea.getReorderedIndexes().get(selindex)]); +// } +// +// private void onFieldSelect(inputType field){ +// //System.out.println(field.name); +// +// binding.editButton.setOnClickListener(v -> { +// binding.editButton.setVisibility(View.GONE); +// binding.addButton.setVisibility(View.GONE); +// binding.upButton.setVisibility(View.GONE); +// binding.downButton.setVisibility(View.GONE); +// +// binding.ValueEditTable.removeAllViews(); +// binding.valueEditContainer.setVisibility(View.VISIBLE); +// TextView tv = new TextView(getContext()); +// +// tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); +// tv.setText(field.name); +// tv.setPadding(8,8,8,8); +// tv.setTextSize(24); +// +// binding.ValueEditTable.addView(tv); +// +// final FieldEditorHelper fe = new FieldEditorHelper( +// getContext(), +// field, +// binding.ValueEditTable +// ); +// +// binding.saveButton.setVisibility(View.VISIBLE); +// binding.saveButton.setOnClickListener(a -> { +// System.out.println(fe.save()); +// defaultVisibility(); +// }); +// +// binding.cancelEditButton.setVisibility(View.VISIBLE); +// binding.cancelEditButton.setOnClickListener(a -> { +// defaultVisibility(); +// }); +// +// binding.deleteButton.setVisibility(View.VISIBLE); +// binding.deleteButton.setOnClickListener(a -> { +// deleteField(field); +// }); +// }); +// +// } +// +// private void deleteField(inputType field){ +// AlertDialog.Builder alert = new AlertDialog.Builder(getContext()); +// alert.setTitle("Warning!"); +// alert.setMessage("Removing a value will result in data being deleted in subsequent field versions!"); +// alert.setNegativeButton("Cancel", null); +// alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { +// @Override +// public void onClick(DialogInterface dialog, int which) { +// defaultVisibility(); +// +// int oldindex = -1; +// for(int i = 0; i < values[values.length - 1].length; i++){ +// if(values[values.length - 1][i].equals(field)){ +// oldindex = i; +// break; +// } +// } +// +// if(oldindex != -1) { +// System.out.println(Arrays.toString(values[values.length - 1])); +// binding.fieldsArea.removeViewAt(selindex); +// binding.fieldsArea.removeElement(oldindex); +// values[values.length - 1] = removeElement(values[values.length - 1], oldindex); +// selindex = -1; +// AlertManager.toast("Removed!"); +// binding.editButton.setVisibility(View.GONE); +// System.out.println(Arrays.toString(values[values.length - 1])); +// //System.out.println(values[values.length-1].length); +// } +// +// } +// }); +// alert.setCancelable(true); +// alert.create().show(); +// } +// +// public inputType[] removeElement(inputType[] src, int i) { +// inputType[] newArray = new inputType[src.length - 1]; +// if (i > 0){ +// System.arraycopy(src, 0, newArray, 0, i); +// } +// +// if (newArray.length > i){ +// System.arraycopy(src, i + 1, newArray, i, newArray.length - i); +// } +// +// return newArray; +// } +// +// +// +// +// +// +// +// +// +// +// private void defaultVisibility() { +// binding.editButton.setVisibility(View.VISIBLE); +// binding.addButton.setVisibility(View.VISIBLE); +// binding.upButton.setVisibility(View.VISIBLE); +// binding.downButton.setVisibility(View.VISIBLE); +// binding.ValueEditTable.removeAllViews(); +// binding.valueEditContainer.setVisibility(View.GONE); +// binding.cancelEditButton.setVisibility(View.GONE); +// binding.deleteButton.setVisibility(View.GONE); +// binding.saveButton.setOnClickListener(this::buttonfunc); +// } +// +// +// +// +// private void addField(View v) { +// AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); +// builder.setTitle("Title"); +// +// final EditText input = new EditText(getContext()); +// input.setInputType(InputType.TYPE_CLASS_TEXT); +// +// builder.setView(input); +// +// builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { +// @Override +// public void onClick(DialogInterface dialog, int which) { +// dialog.cancel(); +// } +// }); +// +// builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { +// @Override +// public void onClick(DialogInterface dialog, int which) { +// String title = input.getText().toString(); +// if(title.isEmpty() || title.isBlank()) { +// AlertManager.addSimpleError("Title cannot be blank!"); +// return; +// } +// addField_Part_2(title); +// } +// }); +// +// builder.show(); +// } +// +// private void addField_Part_2(String title) { +// AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); +// builder.setTitle("Select Type"); +// +// final CustomSpinnerView dropdown = new CustomSpinnerView(getContext()); +// List options = new ArrayList<>(); +// +// options.add("Slider"); +// options.add("Text"); +// options.add("Dropdown"); +// options.add("Tally"); +// options.add("Number"); +// options.add("Checkbox"); +// options.add("Field Position"); +// +// dropdown.setOptions(options, 0); +// dropdown.setTitle("Type"); +// +// builder.setView(dropdown); +// +// builder.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel()); +// builder.setPositiveButton("OK", (dialog, which) -> addField_Part_3(title, dropdown.getIndex())); +// +// builder.show(); +// } +// +// private void addField_Part_3(String title, int typeIndex) { +// switch (typeIndex){ +// case 0: +// sliderType slider = new sliderType(); +// slider.name = title; +// FieldEditorHelper.setSliderParams(slider, FieldEditorHelper.defaultSliderParams); +// addField_Part_4(slider); +// break; +// case 1: +// textType text = new textType(); +// text.name = title; +// FieldEditorHelper.setTextParams(text, FieldEditorHelper.defaultTextParams); +// addField_Part_4(text); +// break; +// case 2: +// dropdownType dropdown = new dropdownType(); +// dropdown.name = title; +// FieldEditorHelper.setDropdownParams(dropdown, FieldEditorHelper.defaultDropdownParams); +// addField_Part_4(dropdown); +// break; +// case 3: +// tallyType tally = new tallyType(); +// tally.name = title; +// FieldEditorHelper.setTallyParams(tally, FieldEditorHelper.defaultTallyParams); +// addField_Part_4(tally); +// break; +// case 4: +// numberType num = new numberType(); +// num.name = title; +// FieldEditorHelper.setNumberParams(num, FieldEditorHelper.defaultNumberParams); +// addField_Part_4(num); +// break; +// case 5: +// checkboxType cb = new checkboxType(); +// cb.name = title; +// FieldEditorHelper.setCheckboxParam(cb, FieldEditorHelper.defaultCheckboxParam); +// addField_Part_4(cb); +// break; +// case 6: +// fieldposType fp = new fieldposType(); +// fp.name = title; +// FieldEditorHelper.setFieldPosParam(fp, FieldEditorHelper.defaultFieldPosParam); +// addField_Part_4(fp); +// break; +// +// } +// +// } +// private void addField_Part_4(inputType field) { +// binding.editButton.setVisibility(View.GONE); +// binding.addButton.setVisibility(View.GONE); +// binding.upButton.setVisibility(View.GONE); +// binding.downButton.setVisibility(View.GONE); +// +// binding.ValueEditTable.removeAllViews(); +// binding.valueEditContainer.setVisibility(View.VISIBLE); +// TextView tv = new TextView(getContext()); +// +// tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); +// tv.setText(field.name); +// tv.setPadding(8,8,8,8); +// tv.setTextSize(24); +// +// binding.ValueEditTable.addView(tv); +// +// final FieldEditorHelper fe = new FieldEditorHelper( +// getContext(), +// field, +// binding.ValueEditTable +// ); +// +// binding.saveButton.setVisibility(View.VISIBLE); +// binding.saveButton.setOnClickListener(a -> { +// inputType[] newValues = new inputType[values[values.length-1].length+1]; +// System.arraycopy(values[values.length-1], 0, newValues, 0, values[values.length-1].length); +// newValues[newValues.length-1] = field; +// values[values.length-1] = newValues; +// +//// AlertManager.alert("Test", String.valueOf(binding.fieldsArea.getReorderedIndexes())); +// +// //TableRow tr = getTableRow(field); +// //binding.fieldsArea.addView(tr); +// addRow(field); +// +// System.out.println(fe.save()); +// defaultVisibility(); +// }); +// +// binding.cancelEditButton.setVisibility(View.VISIBLE); +// binding.cancelEditButton.setOnClickListener(a -> { +// defaultVisibility(); +// }); +// +// } +// +// private @NonNull View getTableRow(inputType field) { +//// TableRow tr = new TableRow(getContext()); +//// TableLayout.LayoutParams rowParams = new TableLayout.LayoutParams( +//// FrameLayout.LayoutParams.WRAP_CONTENT, +//// FrameLayout.LayoutParams.WRAP_CONTENT +//// ); +//// +//// rowParams.setMargins(20,20,20,20); +//// tr.setLayoutParams(rowParams); +//// tr.setPadding(20,20,20,20); +//// tr.setBackgroundColor(unfocused_background_color); +//// +//// TextView tv = new TextView(getContext()); +//// tv.setText(field.get_type_name()); +//// tv.setTextSize(12); +//// tr.addView(tv); +//// +//// tv = new TextView(getContext()); +//// tv.setText(field.name); +//// tv.setTextSize(20); +//// tr.addView(tv); +// FieldDisplay fd = new FieldDisplay(getContext()); +// +// fd.setField(field.createView(getContext(), dataType -> 0)); +// +// +// +// return fd; +// } } diff --git a/app/src/main/java/com/ridgebotics/ridgescout/ui/transfer/TBASelectorFragment.java b/app/src/main/java/com/ridgebotics/ridgescout/ui/transfer/TBASelectorFragment.java index a7b3ccc..f5b5428 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/ui/transfer/TBASelectorFragment.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/ui/transfer/TBASelectorFragment.java @@ -137,6 +137,10 @@ public class TBASelectorFragment extends Fragment { diff = getEventTypeWeight(a.getString("event_type_string")) - getEventTypeWeight(b.getString("event_type_string")); } + if(diff == 0){ + diff = a.getString("key").compareTo(b.getString("key")); + } + return diff; } catch (ParseException | JSONException e) { AlertManager.error(e); diff --git a/app/src/main/java/com/ridgebotics/ridgescout/utility/ReorderableTableLayout.java b/app/src/main/java/com/ridgebotics/ridgescout/utility/ReorderableTableLayout.java deleted file mode 100644 index 8ca98de..0000000 --- a/app/src/main/java/com/ridgebotics/ridgescout/utility/ReorderableTableLayout.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.ridgebotics.ridgescout.utility; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.View; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import android.view.MotionEvent; -import android.widget.TableLayout; - -public class ReorderableTableLayout extends TableLayout { - private boolean reorderingEnabled = false; - private int draggedRowIndex = -1; - private float lastY; - private List rows; - private List reorderedIndices; - private int rowHeight; - - public ReorderableTableLayout(Context context) { - super(context); - init(); - } - - public ReorderableTableLayout(Context context, AttributeSet attrs) { - super(context, attrs); - init(); - } - - private void init() { - rows = new ArrayList<>(); - reorderedIndices = new ArrayList<>(); - } - - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - if (!reorderingEnabled) { - return super.onInterceptTouchEvent(ev); - } - - switch (ev.getAction()) { - case MotionEvent.ACTION_DOWN: - lastY = ev.getY(); - draggedRowIndex = getRowIndexAtY(lastY); - if (draggedRowIndex != -1) { - View draggedRow = getChildAt(draggedRowIndex); - rowHeight = draggedRow.getHeight(); - saveOriginalOrder(); - return true; - } - break; - } - return super.onInterceptTouchEvent(ev); - } - - @Override - public void addView(View child) { - super.addView(child); - reorderedIndices.add(reorderedIndices.size()); - } - - @Override - public void removeAllViews() { - super.removeAllViews(); - reorderedIndices.clear(); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - if (!reorderingEnabled || draggedRowIndex == -1) { - return super.onTouchEvent(event); - } - - float currentY = event.getY(); - int targetIndex = getRowIndexAtY(currentY); - View child = getChildAt(targetIndex); - if(child != null) - getChildAt(targetIndex).callOnClick(); - - switch (event.getAction()) { - case MotionEvent.ACTION_MOVE: - if (targetIndex != -1 && targetIndex != draggedRowIndex) { - updateRowOrder(draggedRowIndex, targetIndex); - draggedRowIndex = targetIndex; - } - lastY = currentY; - break; - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: - draggedRowIndex = -1; - break; - } - return true; - } - - private int getRowIndexAtY(float y) { - for (int i = 0; i < getChildCount(); i++) { - View child = getChildAt(i); - if (y >= child.getTop() && y <= child.getBottom()) { - return i; - } - } - return -1; - } - - private void saveOriginalOrder() { - rows.clear(); - for (int i = 0; i < getChildCount(); i++) { - rows.add(getChildAt(i)); - } - } - - public void updateRowOrder(int fromIndex, int toIndex) { - saveOriginalOrder(); - if (fromIndex < toIndex) { - for (int i = fromIndex; i < toIndex; i++) { - Collections.swap(rows, i, i + 1); - Collections.swap(reorderedIndices, i, i + 1); - } - } else { - for (int i = fromIndex; i > toIndex; i--) { - Collections.swap(rows, i, i - 1); - Collections.swap(reorderedIndices, i, i - 1); - } - } - - removeAllViewsInLayout(); - for (View view : rows) { - addViewInLayout(view, -1, view.getLayoutParams(), true); - } - requestLayout(); - invalidate(); - } - - public void setReorderingEnabled(boolean enabled) { - reorderingEnabled = enabled; - } - - public List getReorderedIndexes() { - return reorderedIndices; - } - - public void removeElement(int unshuffledindex){ - System.out.println(Arrays.toString(new List[]{reorderedIndices})); - - reorderedIndices.remove(unshuffledindex); - - for (int i = 0; i < reorderedIndices.size(); i++) { - if(reorderedIndices.get(i) > unshuffledindex) - reorderedIndices.set(i, reorderedIndices.get(i) - 1); - } - - System.out.println(Arrays.toString(new List[]{reorderedIndices})); - } -} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_settings_fields.xml b/app/src/main/res/layout/fragment_settings_fields.xml index 2fc16ba..e1bcb39 100644 --- a/app/src/main/res/layout/fragment_settings_fields.xml +++ b/app/src/main/res/layout/fragment_settings_fields.xml @@ -19,7 +19,7 @@ android:id="@+id/up_button" android:layout_width="60dp" android:layout_height="wrap_content" - android:text="↑" + android:text="▲" android:textSize="30sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toEndOf="@+id/add_button" /> @@ -38,55 +38,11 @@ android:id="@+id/down_button" android:layout_width="60dp" android:layout_height="wrap_content" - android:text="↓" + android:text="▼" android:textSize="30sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@id/add_button" /> - -