Finish nullable fields

This commit is contained in:
Astatin3
2024-07-17 10:15:00 -06:00
parent 95c8dc45d3
commit e92691e337
10 changed files with 138 additions and 23 deletions
@@ -9,7 +9,7 @@ public abstract class dataType {
public Object value;
public abstract boolean isNull();
// public abstract Object getNullValue();
public abstract Object getNullValue();
public abstract valueTypes getValueType();
public Object get(){
return value;
@@ -1,7 +1,7 @@
package com.astatin3.scoutingapp2025.types.data;
public class intType extends dataType {
private static final int nulval = 255;
public static final int nulval = 255;
public valueTypes getValueType() {
return valueTypes.NUM;
@@ -15,7 +15,10 @@ public class intType extends dataType {
public boolean isNull() {
return ((int) value) == nulval;
}
public static Object getNullValue(){
public Object getNullValue(){
return nulval;
}
public static intType nullify(String name){
return new intType(name, nulval);
}
}
@@ -1,7 +1,7 @@
package com.astatin3.scoutingapp2025.types.data;
public class stringType extends dataType{
private static final String nulval = "Joe";
public static final String nulval = "Joe";
public valueTypes getValueType() {return valueTypes.STRING;}
public stringType(String name, String value){
@@ -11,7 +11,10 @@ public class stringType extends dataType{
public boolean isNull(){
return value.equals(nulval);
}
public static Object getNullValue(){
public Object getNullValue(){
return nulval;
}
public static stringType nullify(String name){
return new stringType(name, nulval);
}
}
@@ -14,6 +14,7 @@ import androidx.annotation.Nullable;
import com.astatin3.scoutingapp2025.R;
import com.astatin3.scoutingapp2025.types.data.dataType;
import com.astatin3.scoutingapp2025.types.data.intType;
import com.astatin3.scoutingapp2025.types.data.stringType;
import com.astatin3.scoutingapp2025.utility.BuiltByteParser;
import com.astatin3.scoutingapp2025.utility.ByteBuilder;
import com.github.mikephil.charting.charts.LineChart;
@@ -105,14 +106,27 @@ public class dropdownType extends inputType {
};
public void setViewValue(Object value) {
if(dropdown == null) return;
if(value.equals(intType.nulval)){
nullify();
return;
}
isBlank = false;
dropdown.setVisibility(View.VISIBLE);
dropdown.selectItemByIndex((int) value);
}
public void nullify(){
isBlank = true;
dropdown.setVisibility(View.GONE);
}
public dataType getViewValue(){
if(dropdown == null) return null;
if(dropdown.getVisibility() == View.GONE) return new intType(name, (int)intType.getNullValue());
if(dropdown.getVisibility() == View.GONE) return new intType(name, intType.nulval);
return new intType(name, dropdown.getSelectedIndex());
}
public void add_individual_view(LinearLayout parent, dataType data){
if(data.isNull()) return;
TextView tv = new TextView(parent.getContext());
tv.setLayoutParams(new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
@@ -152,7 +166,8 @@ public class dropdownType extends inputType {
int[] data_2 = new int[text_options.length];
for(int i = 0; i < data.length; i++)
data_2[(int) data[i].get()]++;
if(!data[i].isNull())
data_2[(int) data[i].get()]++;
List<PieEntry> entries = new ArrayList<>();
for(int i = 0; i < data_2.length; i++) {
@@ -23,7 +23,6 @@ public abstract class inputType {
DROPDOWN,
NOTES_INPUT
}
public String name;
public Object default_value;
public abstract inputTypes getInputType();
@@ -36,8 +35,9 @@ public abstract class inputType {
}
public abstract byte[] encode() throws ByteBuilder.buildingException;
public abstract void decode(byte[] bytes) throws BuiltByteParser.byteParsingExeption;
public abstract View createView(Context context, Function<dataType, Integer> onUpdate);
public boolean isBlank = false;
public abstract void nullify();
public void setViewValue(dataType type){setViewValue(type.get());}
public abstract void setViewValue(Object value);
public abstract dataType getViewValue();
@@ -61,14 +61,25 @@ public class notesType extends inputType {
};
public void setViewValue(Object value) {
if(text == null) return;
if(value.equals(stringType.nulval)){
nullify();
return;
}
isBlank = false;
text.setVisibility(View.VISIBLE);
text.setText((String) value);
}
public void nullify(){
isBlank = true;
text.setVisibility(View.GONE);
}
public dataType getViewValue(){
if(text == null) return null;
if(text.getVisibility() == View.GONE) return new stringType(name, (String) stringType.getNullValue());
if(text.getVisibility() == View.GONE) return new stringType(name, stringType.nulval);
return new stringType(name, text.getText().toString());
}
public void add_individual_view(LinearLayout parent, dataType data){
if(data.isNull()) return;
TextView tv = new TextView(parent.getContext());
tv.setLayoutParams(new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
@@ -80,6 +91,7 @@ public class notesType extends inputType {
parent.addView(tv);
}
public void add_compiled_view(LinearLayout parent, dataType[] data){
// if(data.get().equals(stringType.nulval)) return;
TextView tv = new TextView(parent.getContext());
tv.setLayoutParams(new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
@@ -75,17 +75,28 @@ public class sliderType extends inputType {
}
public void setViewValue(Object value) {
if(slider == null) return;
if(value.equals(intType.nulval)){
nullify();
return;
}
float slider_position = (float) ((int) value-min) / (max-min);
float step_size = (float) 1/(max-min);
int round_position = Math.round(slider_position / step_size);
isBlank = false;
slider.setVisibility(View.VISIBLE);
slider.setValue(round_position*step_size);
}
public dataType getViewValue(){
if(slider == null) return null;
if(slider.getVisibility() == View.GONE) return new intType(name, (int) intType.getNullValue());
if(slider.getVisibility() == View.GONE) return new intType(name, intType.nulval);
return new intType(name, min + (int) (slider.getValue() * (max-min)));
}
public void nullify(){
isBlank = true;
slider.setVisibility(View.GONE);
}
public void add_individual_view(LinearLayout parent, dataType data){
if(data.isNull()) return;
Slider slider = new Slider(parent.getContext());
float slider_position = (float) ((int) data.get()-min) / (max-min);
@@ -139,15 +150,18 @@ public class sliderType extends inputType {
chart.setBackgroundColor(0xff252025);
int[] values = new int[max-min+1];
for (int i = 0; i < data.length; i++)
values[(int) data[i].get()-min]++;
if((int) data[i].get() != intType.nulval)
values[(int) data[i].get()-min]++;
int[] temp = new int[data.length];
ArrayList<Integer> mean_temp = new ArrayList<>();
for (int i = 0; i < data.length; i++)
temp[i] = (int) data[i].get();
if(!data[i].isNull())
mean_temp.add((int) data[i].get());
int[] mean_vals = mean_temp.stream().mapToInt(Integer::intValue).toArray();
List<Entry> entries = new ArrayList<>();
for (int i = 0; i < values.length; i++)
@@ -163,8 +177,8 @@ public class sliderType extends inputType {
// Calculate mean and standard deviation
float mean = calculateMean(temp);
float stdDev = calculateStandardDeviation(temp, mean);
float mean = calculateMean(mean_vals);
float stdDev = calculateStandardDeviation(mean_vals, mean);
// Generate normal distribution curve
List<Entry> normalDistEntries = generateNormalDistribution(mean-min, stdDev, max-min+1, (max-min)/data.length);
@@ -229,6 +229,13 @@ public class teamsView extends ConstraintLayout {
tv.setGravity(Gravity.CENTER_HORIZONTAL);
tv.setText(psda.data.array[a].name);
tv.setTextSize(25);
if(psda.data.array[a].isNull()){
tv.setBackgroundColor(0xffff0000);
tv.setTextColor(0xff000000);
}
ll.addView(tv);
@@ -294,6 +301,12 @@ public class teamsView extends ConstraintLayout {
tv.setGravity(Gravity.CENTER_HORIZONTAL);
tv.setText(psda.data.array[a].name);
tv.setTextSize(25);
if(psda.data.array[a].isNull()){
tv.setBackgroundColor(0xffff0000);
tv.setTextColor(0xff000000);
}
ll.addView(tv);
@@ -47,6 +47,7 @@ public class matchScoutingView extends ConstraintLayout {
boolean edited = false;
TextView[] titles;
inputType[][] values;
inputType[] latest_values;
transferType[][] transferValues;
@@ -157,12 +158,15 @@ public class matchScoutingView extends ConstraintLayout {
asm.stop();
}
titles = new TextView[latest_values.length];
for(int i = 0 ; i < latest_values.length; i++) {
final TextView tv = new TextView(getContext());
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tv.setText(latest_values[i].name);
tv.setPadding(8,8,8,8);
tv.setTextSize(24);
titles[i] = tv;
default_text_color = tv.getCurrentTextColor();
@@ -179,19 +183,19 @@ public class matchScoutingView extends ConstraintLayout {
binding.MatchScoutArea.addView(tv);
int fi = i;
tv.setOnClickListener(p -> {
boolean blank = latest_values[fi].getViewValue().isNull();
// boolean blank = !latest_values[fi].getViewValue().isNull();
System.out.println(blank);
// System.out.println(blank);
if(blank){
asm.update();
if(!latest_values[fi].isBlank){
tv.setBackgroundColor(0xffff0000);
tv.setTextColor(0xff000000);
v.setVisibility(GONE);
latest_values[fi].setViewValue(intType.getNullValue());
latest_values[fi].nullify();
}else{
tv.setBackgroundColor(0x00000000);
tv.setTextColor(default_text_color);
v.setVisibility(VISIBLE);
latest_values[fi].setViewValue(latest_values[fi].default_value);
}
});
@@ -292,6 +296,9 @@ public class matchScoutingView extends ConstraintLayout {
for(int i = 0; i < latest_values.length; i++){
inputType input = latest_values[i];
input.setViewValue(input.default_value);
titles[i].setBackgroundColor(0x00000000);
titles[i].setTextColor(default_text_color);
}
}
@@ -305,6 +312,14 @@ public class matchScoutingView extends ConstraintLayout {
for(int i = 0; i < latest_values.length; i++){
// types[i] = latest_values[i].getViewValue();
latest_values[i].setViewValue(types[i]);
if(latest_values[i].isBlank){
titles[i].setBackgroundColor(0xffff0000);
titles[i].setTextColor(0xff000000);
}else{
titles[i].setBackgroundColor(0x00000000);
titles[i].setTextColor(default_text_color);
}
}
}
@@ -47,6 +47,7 @@ public class pitScoutingView extends ConstraintLayout {
String filename;
String username;
TextView[] titles;
inputType[][] values;
inputType[] latest_values;
transferType[][] transferValues;
@@ -233,18 +234,46 @@ public class pitScoutingView extends ConstraintLayout {
}
private int default_text_color = 0;
private void create_fields() {
if(asm.isRunning){
asm.stop();
}
titles = new TextView[latest_values.length];
for(int i = 0 ; i < latest_values.length; i++) {
TextView tv = new TextView(getContext());
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tv.setText(latest_values[i].name);
tv.setTextSize(24);
tv.setPadding(8,8,8,8);
titles[i] = tv;
binding.pitScoutArea.addView(tv);
default_text_color = tv.getCurrentTextColor();
int fi = i;
tv.setOnClickListener(p -> {
// boolean blank = !latest_values[fi].getViewValue().isNull();
// System.out.println(blank);
asm.update();
if(!latest_values[fi].isBlank){
tv.setBackgroundColor(0xffff0000);
tv.setTextColor(0xff000000);
latest_values[fi].nullify();
}else{
tv.setBackgroundColor(0x00000000);
tv.setTextColor(default_text_color);
latest_values[fi].setViewValue(latest_values[fi].default_value);
}
});
View v = latest_values[i].createView(getContext(), new Function<dataType, Integer>() {
@Override
public Integer apply(dataType dataType) {
@@ -263,6 +292,9 @@ public class pitScoutingView extends ConstraintLayout {
for(int i = 0; i < latest_values.length; i++){
inputType input = latest_values[i];
input.setViewValue(input.default_value);
titles[i].setBackgroundColor(0x00000000);
titles[i].setTextColor(default_text_color);
}
}
@@ -274,6 +306,14 @@ public class pitScoutingView extends ConstraintLayout {
for(int i = 0; i < latest_values.length; i++){
// types[i] = latest_values[i].getViewValue();
latest_values[i].setViewValue(types[i]);
if(latest_values[i].isBlank){
titles[i].setBackgroundColor(0xffff0000);
titles[i].setTextColor(0xff000000);
}else{
titles[i].setBackgroundColor(0x00000000);
titles[i].setTextColor(default_text_color);
}
}
}
}