Make scouting data fields actually work well.

This commit is contained in:
astatin3
2024-06-29 02:52:17 -06:00
parent 485205f35c
commit 28a5d909a9
6 changed files with 182 additions and 92 deletions
+1 -3
View File
@@ -2,15 +2,13 @@
Ridgebotics 2025 scouting app in Android Ridgebotics 2025 scouting app in Android
TODO: TODO:
- Clean up matchScoutingView class, and make it provide code for both pit and match scouting - Copy matchScoutingView to create pitScoutingView
- Separate the inputTypes classes into their own files, and integrate the some of the stuff from matchScoutingView to make the code cleaner.
- Make the file browser UI - Make the file browser UI
- Add white border around the datamatrix code to allow file transfer in dark mode - Add white border around the datamatrix code to allow file transfer in dark mode
- Fix the code scanning progress indicator - Fix the code scanning progress indicator
- Make pit and match data field builder UIs. I don't want to have to keep editing a variable - Make pit and match data field builder UIs. I don't want to have to keep editing a variable
Also TODO: Also TODO:
- Copy matchScoutingView to create pitScoutingView
- Add more types of data fields. - Add more types of data fields.
- Make the "Search" menu - Make the "Search" menu
- Make the "Compile" menu - Make the "Compile" menu
@@ -1,9 +1,28 @@
package com.astatin3.scoutingapp2025.scoutingData; package com.astatin3.scoutingapp2025.scoutingData;
import android.app.slice.Slice;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.astatin3.scoutingapp2025.SettingsVersionStack.latestSettings;
import com.astatin3.scoutingapp2025.utility.BuiltByteParser; import com.astatin3.scoutingapp2025.utility.BuiltByteParser;
import com.astatin3.scoutingapp2025.utility.ByteBuilder; import com.astatin3.scoutingapp2025.utility.ByteBuilder;
import com.google.android.material.slider.Slider;
import com.skydoves.powerspinner.IconSpinnerAdapter;
import com.skydoves.powerspinner.IconSpinnerItem;
import com.skydoves.powerspinner.OnSpinnerItemSelectedListener;
import com.skydoves.powerspinner.PowerSpinnerView;
import com.skydoves.powerspinner.SpinnerGravity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
public class ScoutingVersion { public class ScoutingVersion {
public static final int slider_type_id = 255; public static final int slider_type_id = 255;
@@ -34,6 +53,11 @@ public class ScoutingVersion {
} }
public abstract byte[] encode() throws ByteBuilder.buildingException; public abstract byte[] encode() throws ByteBuilder.buildingException;
public abstract void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption; public abstract void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption;
public abstract View createView(Context context, Function<dataType, Integer> onUpdate);
public void setViewValue(dataType type){setViewValue(type.get());}
public abstract void setViewValue(Object value);
public abstract dataType getViewValue();
} }
// public class usernameType extends inputType { // public class usernameType extends inputType {
@@ -77,8 +101,37 @@ public class ScoutingVersion {
min = (int) objects.get(2).get(); min = (int) objects.get(2).get();
max = (int) objects.get(3).get(); max = (int) objects.get(3).get();
} }
public Slider slider = null;
public View createView(Context context, Function<dataType, Integer> onUpdate){
slider = new Slider(context);
setViewValue(default_value);
slider.setStepSize((float) 1 / max);
slider.addOnChangeListener(new Slider.OnChangeListener() {
@Override
public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
onUpdate.apply(getViewValue());
}
});
return slider;
}
public void setViewValue(Object value) {
if(slider == null) return;
float slider_position = (float) ((int) value-min) / (max-min);
float step_size = (float) 1/max;
int round_position = Math.round(slider_position / step_size);
slider.setValue(round_position*step_size);
}
public dataType getViewValue(){
if(slider == null) return null;
return new intType(name, min + (int) (slider.getValue() * (max-min)));
}
} }
public class dropdownType extends inputType { public class dropdownType extends inputType {
public String[] text_options; public String[] text_options;
public int get_byte_id() {return dropdownType;} public int get_byte_id() {return dropdownType;}
@@ -105,6 +158,57 @@ public class ScoutingVersion {
default_value = objects.get(1).get(); default_value = objects.get(1).get();
text_options = (String[]) objects.get(2).get(); text_options = (String[]) objects.get(2).get();
} }
public PowerSpinnerView dropdown = null;
public View createView(Context context, Function<dataType, Integer> onUpdate){
dropdown = new PowerSpinnerView(context);
List<IconSpinnerItem> iconSpinnerItems = new ArrayList<>();
for(int i = 0; i < text_options.length; i++){
iconSpinnerItems.add(new IconSpinnerItem(text_options[i]));
}
IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(dropdown);
dropdown.setSpinnerAdapter(iconSpinnerAdapter);
dropdown.setItems(iconSpinnerItems);
dropdown.selectItemByIndex((int) default_value);
dropdown.setPadding(10,10,10,10);
dropdown.setBackgroundColor(0xf0000000);
dropdown.setTextSize(15);
dropdown.setArrowGravity(SpinnerGravity.END);
dropdown.setArrowPadding(8);
dropdown.setSpinnerItemHeight(46);
dropdown.setSpinnerPopupElevation(14);
dropdown.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener<IconSpinnerItem>() {
@Override
public void onItemSelected(int oldIndex, @Nullable IconSpinnerItem oldItem, int newIndex,
IconSpinnerItem newItem) {
onUpdate.apply(getViewValue());
}
});
// dropdown.setLifecycleOwner(context.life);
// slider.addOnChangeListener(new Slider.OnChangeListener() {
// @Override
// public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
// onUpdate.apply(getViewValue());
// }
// });
return dropdown;
};
public void setViewValue(Object value) {
if(dropdown == null) return;
dropdown.selectItemByIndex((int) value);
}
public dataType getViewValue(){
if(dropdown == null) return null;
return new intType(name, dropdown.getSelectedIndex());
}
} }
public class notesType extends inputType { public class notesType extends inputType {
@@ -129,6 +233,30 @@ public class ScoutingVersion {
name = (String) objects.get(0).get(); name = (String) objects.get(0).get();
default_value = objects.get(1).get(); default_value = objects.get(1).get();
} }
public EditText text = null;
public View createView(Context context, Function<dataType, Integer> onUpdate){
text = new EditText(context);
text.setText((String)default_value);
text.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
onUpdate.apply(getViewValue()); }
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
return text;
};
public void setViewValue(Object value) {
if(text == null) return;
text.setText((String) value);
}
public dataType getViewValue(){
if(text == null) return null;
return new stringType(name, text.getText().toString());
}
} }
@@ -259,7 +387,6 @@ public class ScoutingVersion {
new_values[i] = create_transfer((createTransferType) tv); new_values[i] = create_transfer((createTransferType) tv);
continue; continue;
} }
System.out.println(new_values[i]);
} }
this.array = new_values; this.array = new_values;
version++; version++;
@@ -297,14 +424,12 @@ public class ScoutingVersion {
private dataType create_transfer(createTransferType tv){ private dataType create_transfer(createTransferType tv){
inputType it = get_input_type_by_name(version+1, tv.name); inputType it = get_input_type_by_name(version+1, tv.name);
// System.out.println(tv.name);
switch (it.getValueType()){ switch (it.getValueType()){
case NUM: case NUM:
return new intType(it.name, (int) it.default_value); return new intType(it.name, (int) it.default_value);
case STRING: case STRING:
return new stringType(it.name, (String) it.default_value); return new stringType(it.name, (String) it.default_value);
} }
System.out.println(2);
return null; return null;
} }
@@ -18,7 +18,12 @@ public class fields {
sv.new notesType("notes", "<no-notes>"), sv.new notesType("notes", "<no-notes>"),
},{ },{
sv.new sliderType("How good is robot", 5, 0, 10), sv.new sliderType("How good is robot", 5, 0, 10),
sv.new sliderType("Test", 1, 0, 10), sv.new sliderType("Test", 128, 64, 256),
sv.new notesType("notes", "<no-notes>"),
},{
sv.new sliderType("How good is robot", 5, 0, 10),
sv.new sliderType("Test", 128, 64, 256),
sv.new dropdownType("test-dropdown", new String[]{"Test1", "test2", "Three"}, 1),
sv.new notesType("notes", "<no-notes>"), sv.new notesType("notes", "<no-notes>"),
} }
}; };
@@ -0,0 +1,19 @@
package com.astatin3.scoutingapp2025.ui.scouting;
import android.content.Context;
import android.util.AttributeSet;
import androidx.constraintlayout.widget.ConstraintLayout;
public class ScoutingDataView extends ConstraintLayout {
public ScoutingDataView(Context context) {
super(context);
}
public ScoutingDataView(Context context, AttributeSet attributeSet){
super(context, attributeSet);
}
public void load(String fieldsFilename){
}
}
@@ -23,6 +23,7 @@ import com.google.android.material.slider.Slider;
import com.skydoves.powerspinner.PowerSpinnerView; import com.skydoves.powerspinner.PowerSpinnerView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.function.Function;
public class matchScoutingView extends ConstraintLayout { public class matchScoutingView extends ConstraintLayout {
public matchScoutingView(Context context) { public matchScoutingView(Context context) {
@@ -32,8 +33,8 @@ public class matchScoutingView extends ConstraintLayout {
super(context, attributeSet); super(context, attributeSet);
} }
int unsaved_color = 0x60ff0000; private static final int unsaved_color = 0x60ff0000;
int saved_color = 0x6000ff00; private static final int saved_color = 0x6000ff00;
FragmentScoutingBinding binding; FragmentScoutingBinding binding;
String alliance_position; String alliance_position;
@@ -131,7 +132,7 @@ public class matchScoutingView extends ConstraintLayout {
binding.MatchScoutArea.removeView(views.get(i)); binding.MatchScoutArea.removeView(views.get(i));
} }
views = new ArrayList<>(); // views = new ArrayList<>();
create_fields(); create_fields();
update_scouting_data(); update_scouting_data();
@@ -141,46 +142,28 @@ public class matchScoutingView extends ConstraintLayout {
private void create_fields(){ private void create_fields(){
if(asm.isRunning){
asm.stop();
}
for(int i = 0 ; i < latest_values.length; i++) { for(int i = 0 ; i < latest_values.length; i++) {
TextView tv = new TextView(getContext()); TextView tv = new TextView(getContext());
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tv.setText(latest_values[i].name);
tv.setTextSize(24); tv.setTextSize(24);
binding.MatchScoutArea.addView(tv); binding.MatchScoutArea.addView(tv);
// views.add(tv);
switch (latest_values[i].getInputType()) { View v = latest_values[i].createView(getContext(), new Function<ScoutingVersion.dataType, Integer>() {
case SLIDER: @Override
ScoutingVersion.sliderType sliderType = (ScoutingVersion.sliderType) latest_values[i]; public Integer apply(ScoutingVersion.dataType dataType) {
// dataTypes.add() // edited = true;
tv.setText(sliderType.name); if(asm.isRunning)
update_asm();
return 0;
}
});
Slider slider = new Slider(getContext()); binding.MatchScoutArea.addView(v);
slider.setStepSize((float) 1 / sliderType.max);
slider.setValue((int) sliderType.default_value / (float) sliderType.max);
slider.addOnChangeListener(new Slider.OnChangeListener() {
@Override
public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
System.out.println(value * sliderType.max);
update_asm();
}
});
binding.MatchScoutArea.addView(slider);
views.add(slider);
break;
case DROPDOWN:
ScoutingVersion.dropdownType dropdownType = (ScoutingVersion.dropdownType) latest_values[i];
tv.setText(dropdownType.name);
views.add(new PowerSpinnerView(getContext()));
break;
case NOTES_INPUT:
ScoutingVersion.notesType notesType = (ScoutingVersion.notesType) latest_values[i];
tv.setText(notesType.name);
views.add(new EditText(getContext()));
break;
}
} }
} }
@@ -194,8 +177,6 @@ public class matchScoutingView extends ConstraintLayout {
binding.matchnum.setText(String.valueOf(cur_match_num+1)); binding.matchnum.setText(String.valueOf(cur_match_num+1));
System.out.println(cur_match_num);
if(cur_match_num <= 0){ if(cur_match_num <= 0){
binding.backButton.setVisibility(View.GONE); binding.backButton.setVisibility(View.GONE);
}else{ }else{
@@ -275,14 +256,9 @@ public class matchScoutingView extends ConstraintLayout {
public void default_fields(){ public void default_fields(){
for(int i = 0; i < views.size(); i++){ for(int i = 0; i < latest_values.length; i++){
if(views.get(i).getClass() == Slider.class){ ScoutingVersion.inputType input = latest_values[i];
ScoutingVersion.sliderType sliderType = (ScoutingVersion.sliderType) latest_values[i]; input.setViewValue(input.default_value);
((Slider) views.get(i)).setValue((int) sliderType.default_value / (float) sliderType.max);
}
// } else if (views.get(i).getClass() == .class) {
//
// }
} }
} }
@@ -293,27 +269,10 @@ public class matchScoutingView extends ConstraintLayout {
ScoutingDataWriter.ParsedScoutingDataResult psdr = ScoutingDataWriter.load(filename, values, transferValues); ScoutingDataWriter.ParsedScoutingDataResult psdr = ScoutingDataWriter.load(filename, values, transferValues);
ScoutingVersion.dataType[] types = psdr.data.array; ScoutingVersion.dataType[] types = psdr.data.array;
for(int i = 0; i < views.size(); i++){ for(int i = 0; i < latest_values.length; i++){
// types[i] = latest_values[i].getViewValue();
View view = views.get(i); latest_values[i].setViewValue(types[i]);
Class<? extends View> c = view.getClass();
if(c == Slider.class){
ScoutingVersion.sliderType sliderType = (ScoutingVersion.sliderType) latest_values[i];
((Slider) view).setValue((float) (sliderType.min + (int) types[i].get()) / (sliderType.max-sliderType.min));
// types[i] = fields.sv.new intType(latest_values[i].name, (int) ((Slider) view).getValue());
} else if (c == PowerSpinnerView.class) {
// types[i] = fields.sv.new intType(latest_values[i].name, 0);
} else if (c == EditText.class) {
// types[i] = fields.sv.new stringType(latest_values[i].name, "Test String");
}
} }
// System.out.println(ScoutingDataWriter.save(values.length, username, filename, types));
} }
@@ -322,26 +281,10 @@ public class matchScoutingView extends ConstraintLayout {
ScoutingVersion.dataType[] types = new ScoutingVersion.dataType[latest_values.length]; ScoutingVersion.dataType[] types = new ScoutingVersion.dataType[latest_values.length];
for(int i = 0; i < views.size(); i++){ for(int i = 0; i < latest_values.length; i++){
types[i] = latest_values[i].getViewValue();
View view = views.get(i);
Class<? extends View> c = view.getClass();
if(c == Slider.class){
ScoutingVersion.sliderType sliderType = (ScoutingVersion.sliderType) latest_values[i];
types[i] = fields.sv.new intType(latest_values[i].name,
sliderType.min + (int)(((Slider) view).getValue() * (sliderType.max-sliderType.min)));
} else if (c == PowerSpinnerView.class) {
types[i] = fields.sv.new intType(latest_values[i].name, 0);
} else if (c == EditText.class) {
types[i] = fields.sv.new stringType(latest_values[i].name, "Test String");
}
} }
System.out.println(types.length);
System.out.println(ScoutingDataWriter.save(values.length-1, username, filename, types)); System.out.println(ScoutingDataWriter.save(values.length-1, username, filename, types));
} }
} }
@@ -88,7 +88,7 @@ public class settingsFragment extends Fragment {
IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(spinnerView); IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(spinnerView);
spinnerView.setSpinnerAdapter(iconSpinnerAdapter); spinnerView.setSpinnerAdapter(iconSpinnerAdapter);
spinnerView.setItems(iconSpinnerItems); spinnerView.setItems(iconSpinnerItems);
spinnerView.setLifecycleOwner(this); // spinnerView.setLifecycleOwner(this);
if(!iconSpinnerItems.isEmpty() && target_index != -1){ if(!iconSpinnerItems.isEmpty() && target_index != -1){
spinnerView.selectItemByIndex(target_index); spinnerView.selectItemByIndex(target_index);