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 ef87f34..5382b37 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 @@ -29,6 +29,7 @@ import com.github.mikephil.charting.data.LineDataSet; import com.github.mikephil.charting.data.PieData; import com.github.mikephil.charting.data.PieDataSet; import com.github.mikephil.charting.data.PieEntry; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import java.util.ArrayList; import java.util.Arrays; @@ -105,16 +106,14 @@ public class DropdownType extends FieldType { public void add_individual_view(LinearLayout parent, RawDataType data){ if(data.isNull()) return; - TextView tv = new TextView(parent.getContext()); - tv.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setPadding(20,20,20,20); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText(text_options[(int) data.get()]); - tv.setTextSize(18); - parent.addView(tv); + + parent.addView( + new TextViewBuilder(parent.getContext(), text_options[(int) data.get()]) + .layout_match_wrap() + .padding(20) + .size(18) + .align_center() + .build()); } 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 42b74ca..951af2f 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 @@ -29,6 +29,7 @@ import com.ridgebotics.ridgescout.types.data.RawDataType; import com.ridgebotics.ridgescout.types.data.IntType; import com.ridgebotics.ridgescout.utility.BuiltByteParser; import com.ridgebotics.ridgescout.utility.ByteBuilder; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import java.util.ArrayList; import java.util.List; @@ -118,16 +119,11 @@ public class NumberType extends FieldType { public void add_individual_view(LinearLayout parent, RawDataType data){ if(data.isNull()) return; - - TextView tv = new TextView(parent.getContext()); - tv.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText(String.valueOf((int) data.get())); - tv.setTextSize(24); - parent.addView(tv); + parent.addView(new TextViewBuilder(parent.getContext(), String.valueOf((int) data.get())) + .layout_match_wrap() + .align_center() + .size(24) + .build()); } 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 c504e65..3231afa 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 @@ -29,6 +29,7 @@ import com.github.mikephil.charting.components.Legend; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.data.LineDataSet; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import java.util.ArrayList; import java.util.Collections; @@ -103,16 +104,11 @@ public class TallyType extends FieldType { public void add_individual_view(LinearLayout parent, RawDataType data){ if(data.isNull()) return; - - TextView tv = new TextView(parent.getContext()); - tv.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText(String.valueOf((int) data.get())); - tv.setTextSize(24); - parent.addView(tv); + parent.addView(new TextViewBuilder(parent.getContext(), String.valueOf((int) data.get())) + .layout_match_wrap() + .align_center() + .size(24) + .build()); } @@ -344,16 +340,12 @@ public class TallyType extends FieldType { row = new TableRow(parent.getContext()); CandlestickView view = views.get(i); - TextView teamNum = new TextView(parent.getContext()); - TableRow.LayoutParams params = new TableRow.LayoutParams(); - params.gravity = Gravity.CENTER; - teamNum.setLayoutParams(params); - teamNum.setPadding(10,10,10,10); - teamNum.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Headline6); - teamNum.setText(String.valueOf(view.teamNum)); + row.addView(new TextViewBuilder(parent.getContext(), String.valueOf(view.teamNum)) + .align_center() + .padding(10) + .h6() + .build()); - - row.addView(teamNum); row.addView(view); parent.addView(row); 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 36977d7..127c9df 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 @@ -28,6 +28,7 @@ import com.github.mikephil.charting.components.Legend; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.data.LineDataSet; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import java.util.ArrayList; import java.util.List; @@ -112,15 +113,11 @@ public class TextType extends FieldType { public void add_individual_view(LinearLayout parent, RawDataType data){ if(data.isNull()) return; - TextView tv = new TextView(parent.getContext()); - tv.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText((String) data.get()); - tv.setTextSize(18); - parent.addView(tv); + parent.addView(new TextViewBuilder(parent.getContext(), (String) data.get()) + .layout_match_wrap() + .align_center() + .size(18) + .build()); } @@ -144,25 +141,20 @@ public class TextType extends FieldType { positive_mean = 0; count = 0; - positive_text = new TextView(parent.getContext()); - positive_text.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - positive_text.setGravity(Gravity.CENTER_HORIZONTAL); - positive_text.setTextSize(20); + positive_text = new TextViewBuilder(parent.getContext()) + .align_center() + .size(20) + .build(); + parent.addView(positive_text); for (int i = 0; i < data.length; i++){ if (!data[i].isNull()) { - SentimentAnalysis.analyse((String) data[i].get(), new SentimentAnalysis.resultCallback() { - @Override - public void onFinish(float sentiment) { - positive_mean += sentiment; - count++; + SentimentAnalysis.analyse((String) data[i].get(), sentiment -> { + positive_mean += sentiment; + count++; - positive_text.setText("Sentiment: " + (positive_mean / count)); - } + positive_text.setText("Sentiment: " + (positive_mean / count)); }); } } diff --git a/app/src/main/java/com/ridgebotics/ridgescout/ui/data/TeamsFragment.java b/app/src/main/java/com/ridgebotics/ridgescout/ui/data/TeamsFragment.java index aee9ef1..5ff9277 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/ui/data/TeamsFragment.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/ui/data/TeamsFragment.java @@ -33,6 +33,7 @@ import com.ridgebotics.ridgescout.types.data.RawDataType; import com.ridgebotics.ridgescout.types.frcTeam; import com.ridgebotics.ridgescout.utility.DataManager; import com.ridgebotics.ridgescout.utility.FileEditor; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import java.util.ArrayList; import java.util.List; @@ -119,49 +120,34 @@ public class TeamsFragment extends Fragment { // ll.addView(new MaterialDivider(getContext())); if(!FileEditor.fileExist(filename)){ - TextView tv = new TextView(getContext()); - tv.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText("No pit data has been collected!"); - tv.setTextSize(23); - binding.pitArea.addView(tv); + binding.pitArea.addView(new TextViewBuilder(getContext(), "No pit data has been collected!") + .layout_match_wrap().align_center().size(23).build()); return; } ScoutingDataWriter.ParsedScoutingDataResult psda = ScoutingDataWriter.load(filename, pit_values, pit_transferValues); - TextView tv = new TextView(getContext()); - tv.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setPadding(0, 20, 0, 5); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText("Pit scouting by " + psda.username); - tv.setTextSize(30); - binding.pitArea.addView(tv); + + binding.pitArea.addView(new TextViewBuilder(getContext(), "Pit scouting by " + psda.username) + .layout_match_wrap() + .padding(0, 20, 0, 5) + .align_center() + .size(30) + .build() + ); for (int a = 0; a < psda.data.array.length; a++) { - tv = new TextView(getContext()); - tv.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText(pit_latest_values[a].name); - tv.setTextSize(25); + TextViewBuilder tvb = new TextViewBuilder(getContext(), pit_latest_values[a].name) + .align_center() + .layout_match_wrap() + .size(25); if(psda.data.array[a].isNull()){ - tv.setBackgroundColor(toggletitle_unselected); - tv.setTextColor(toggletitle_black_background); + tvb.tv.setBackgroundColor(toggletitle_unselected); + tvb.tv.setTextColor(toggletitle_black_background); } - - - binding.pitArea.addView(tv); + binding.pitArea.addView(tvb.build()); pit_latest_values[a].add_individual_view(binding.pitArea, psda.data.array[a]); @@ -177,15 +163,11 @@ public class TeamsFragment extends Fragment { String[] files = FileEditor.getMatchesByTeamNum(evcode, team.teamNumber); if(files.length == 0){ - TextView tv = new TextView(getContext()); - tv.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText("No match data has been collected!"); - tv.setTextSize(23); - binding.matchArea.addView(tv); + binding.matchArea.addView(new TextViewBuilder(getContext(), "No match data has been collected!") + .layout_match_wrap() + .align_center() + .size(23) + .build()); return; } @@ -238,33 +220,28 @@ public class TeamsFragment extends Fragment { ScoutingDataWriter.ParsedScoutingDataResult psda = ScoutingDataWriter.load(files[matchIndex], match_values, match_transferValues); - TextView tv = new TextView(getContext()); - tv.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setPadding(0, 40, 0, 5); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText("M" + (match_num) + " " + split[2] + "-" + split[3] + " by " + psda.username); - tv.setTextSize(30); - binding.matchArea.addView(tv); + + binding.matchArea.addView( + new TextViewBuilder(getContext(), "M" + (match_num) + " " + split[2] + "-" + split[3] + " by " + psda.username) + .align_center() + .size(30) + .padding(0,0,40,5) + .build() + + ); + for (int i = 0; i < psda.data.array.length; i++) { - tv = new TextView(getContext()); - tv.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText(match_latest_values[i].name); - tv.setTextSize(25); + TextViewBuilder tv = new TextViewBuilder(getContext(), match_latest_values[i].name) + .align_center() + .size(25); if (psda.data.array[i].isNull()) { - tv.setBackgroundColor(toggletitle_unselected); - tv.setTextColor(toggletitle_black_background); + tv.tv.setBackgroundColor(toggletitle_unselected); + tv.tv.setTextColor(toggletitle_black_background); } - binding.matchArea.addView(tv); + binding.matchArea.addView(tv.build()); if(psda.data.array[i] != null) @@ -296,16 +273,14 @@ public class TeamsFragment extends Fragment { } for(int i = 0; i < match_latest_values.length; i++){ - TextView tv = new TextView(getContext()); - tv.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setPadding(0, 20, 0, 5); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText(match_latest_values[i].name); - tv.setTextSize(30); - binding.matchArea.addView(tv); + + binding.matchArea.addView( + new TextViewBuilder(getContext(), match_latest_values[i].name) + .align_center() + .padding(0, 0, 20, 5) + .size(30) + .build() + ); if(data[i] != null) match_latest_values[i].add_compiled_view(binding.matchArea, data[i]); @@ -331,16 +306,14 @@ public class TeamsFragment extends Fragment { } for(int i = 0; i < match_latest_values.length; i++){ - TextView tv = new TextView(getContext()); - tv.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setPadding(0, 20, 0, 5); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText(match_latest_values[i].name); - tv.setTextSize(30); - binding.matchArea.addView(tv); + + binding.matchArea.addView( + new TextViewBuilder(getContext(), match_latest_values[i].name) + .align_center() + .size(30) + .padding(0,0,20,5) + .build() + ); if(data[i] != null) match_latest_values[i].add_history_view(binding.matchArea, data[i]); diff --git a/app/src/main/java/com/ridgebotics/ridgescout/ui/scouting/EventFragment.java b/app/src/main/java/com/ridgebotics/ridgescout/ui/scouting/EventFragment.java index 87c067e..2d7589b 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/ui/scouting/EventFragment.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/ui/scouting/EventFragment.java @@ -30,6 +30,7 @@ import com.ridgebotics.ridgescout.utility.FileEditor; import com.ridgebotics.ridgescout.types.frcEvent; import com.ridgebotics.ridgescout.types.frcMatch; import com.ridgebotics.ridgescout.utility.SettingsManager; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import java.util.ArrayList; import java.util.Arrays; @@ -59,11 +60,10 @@ public class EventFragment extends Fragment { add_match_scouting(event); } private void addTableText(TableRow tr, String textStr){ - TextView text = new TextView(getContext()); - text.setTextSize(18); - text.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); // Text align center - text.setText(textStr); - tr.addView(text); + tr.addView(new TextViewBuilder(getContext(), textStr) + .align_center() + .size(18) + .build()); } public void add_pit_scouting(frcEvent event){ @@ -94,33 +94,32 @@ public class EventFragment extends Fragment { tr = new TableRow(getContext()); } - TextView text = new TextView(getContext()); - text.setTextSize(18); - text.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); + TextViewBuilder text = new TextViewBuilder(getContext(), String.valueOf(num)) + .size(18) + .align_center(); - text.setText(String.valueOf(num)); final String filename = event.eventCode + "-" + num + ".pitscoutdata"; if(FileEditor.fileExist(filename)){ final boolean[] rescout = {DataManager.rescout_list.contains(filename)}; - text.setBackgroundColor(rescout[0] ? color_rescout : color_found); + text.tv.setBackgroundColor(rescout[0] ? color_rescout : color_found); - text.setOnLongClickListener(view -> { + text.tv.setOnLongClickListener(view -> { rescout[0] = !rescout[0]; if(rescout[0]) { - text.setBackgroundColor(color_rescout); + text.tv.setBackgroundColor(color_rescout); DataManager.rescout_list.add(filename); }else{ - text.setBackgroundColor(color_found); + text.tv.setBackgroundColor(color_found); DataManager.rescout_list.remove(filename); } DataManager.save_rescout_list(); return true; }); }else{ - text.setBackgroundColor(color_not_found); + text.tv.setBackgroundColor(color_not_found); } - tr.addView(text); + tr.addView(text.build()); } if(tr != null) binding.teamsTable.addView(tr); @@ -153,10 +152,6 @@ public class EventFragment extends Fragment { addTableText(tr, String.valueOf(match.matchIndex)); // for(int i=0;i<6;i++){ - TextView text = new TextView(getContext()); - text.setTextSize(18); - text.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - int team_num; String alliance_position; @@ -168,20 +163,23 @@ public class EventFragment extends Fragment { alliance_position = "blue-"+(i-2); } - text.setText(String.valueOf(team_num)); + TextViewBuilder text = new TextViewBuilder(getContext(), String.valueOf(team_num)) + .size(18) + .align_center(); + final String filename = event.eventCode + "-" + match.matchIndex + "-" + alliance_position + "-" + team_num + ".matchscoutdata"; if(FileEditor.fileExist(filename)){ final boolean[] rescout = {DataManager.rescout_list.contains(filename)}; - text.setBackgroundColor(rescout[0] ? color_rescout : color_found); + text.tv.setBackgroundColor(rescout[0] ? color_rescout : color_found); - text.setOnLongClickListener(view -> { + text.tv.setOnLongClickListener(view -> { rescout[0] = !rescout[0]; if(rescout[0]) { - text.setBackgroundColor(color_rescout); + text.tv.setBackgroundColor(color_rescout); DataManager.rescout_list.add(filename); }else{ - text.setBackgroundColor(color_found); + text.tv.setBackgroundColor(color_found); DataManager.rescout_list.remove(filename); } DataManager.save_rescout_list(); @@ -189,9 +187,9 @@ public class EventFragment extends Fragment { }); }else{ - text.setBackgroundColor(color_not_found); + text.tv.setBackgroundColor(color_not_found); } - tr.addView(text); + tr.addView(text.build()); } binding.matchTable.addView(tr); diff --git a/app/src/main/java/com/ridgebotics/ridgescout/ui/scouting/MatchScoutingFragment.java b/app/src/main/java/com/ridgebotics/ridgescout/ui/scouting/MatchScoutingFragment.java index c02f159..21457f7 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/ui/scouting/MatchScoutingFragment.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/ui/scouting/MatchScoutingFragment.java @@ -33,6 +33,7 @@ import com.ridgebotics.ridgescout.utility.AlertManager; import com.ridgebotics.ridgescout.utility.AutoSaveManager; import com.ridgebotics.ridgescout.utility.DataManager; import com.ridgebotics.ridgescout.utility.FileEditor; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; // Fragment for match scouting data editing. public class MatchScoutingFragment extends Fragment { @@ -59,10 +60,12 @@ public class MatchScoutingFragment extends Fragment { binding.matchTeamCard.setVisibility(View.VISIBLE); if(DataManager.match_values == null || DataManager.match_values.length == 0){ - TextView tv = new TextView(getContext()); - tv.setText("Failed to load fields.\nTry to either download or create match scouting fields."); - tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - binding.MatchScoutArea.addView(tv); + + binding.MatchScoutArea.addView( + new TextViewBuilder(getContext(), "Failed to load fields.\nTry to either download or create match scouting fields.") + .align_center() + .build()); + return binding.getRoot(); } diff --git a/app/src/main/java/com/ridgebotics/ridgescout/ui/scouting/ScoutingFragment.java b/app/src/main/java/com/ridgebotics/ridgescout/ui/scouting/ScoutingFragment.java index 380930a..e6ddc67 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/ui/scouting/ScoutingFragment.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/ui/scouting/ScoutingFragment.java @@ -28,6 +28,7 @@ import com.ridgebotics.ridgescout.utility.FileEditor; import com.ridgebotics.ridgescout.utility.SettingsManager; import com.ridgebotics.ridgescout.databinding.FragmentScoutingBinding; import com.ridgebotics.ridgescout.utility.DataManager; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import java.util.ArrayList; import java.util.Set; @@ -169,16 +170,15 @@ public class ScoutingFragment extends Fragment { binding.textMatchAlliance.setText("Match: " + (curMatchNum+1) + ", " + SettingsManager.getAllyPos()); binding.textRescoutIndicator.setText("Things to rescout: " + DataManager.rescout_list.size()); - TextView nextMatchText = new TextView(getContext()); - nextMatchText.setText("Our next match: Match " + nextMatch); - nextMatchText.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Body1); - binding.infoBox.addView(nextMatchText); + binding.infoBox.addView(new TextViewBuilder(getContext(), "Our next match: Match " + nextMatch) + .body1() + .build()); int informedBy = event.getMostInformedBy(teamNum, curMatchNum); - TextView mostInformedText = new TextView(getContext()); - mostInformedText.setText("Most informed by: Match " + informedBy); - mostInformedText.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Body1); - binding.infoBox.addView(mostInformedText); + + binding.infoBox.addView(new TextViewBuilder(getContext(), "Most informed by: Match " + informedBy) + .body1() + .build()); } } \ No newline at end of file diff --git a/app/src/main/java/com/ridgebotics/ridgescout/ui/settings/FieldEditorHelper.java b/app/src/main/java/com/ridgebotics/ridgescout/ui/settings/FieldEditorHelper.java index c04da59..018a9ad 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/ui/settings/FieldEditorHelper.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/ui/settings/FieldEditorHelper.java @@ -19,6 +19,7 @@ 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.utility.AlertManager; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import java.lang.reflect.Field; import java.util.UUID; @@ -397,11 +398,11 @@ public class FieldEditorHelper { this.t = t; views = new View[types.length]; for(int i = 0; i < types.length; i++){ - TextView tv = new TextView(c); - tv.setText(types[i].name); - tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - tv.setTextSize(20); - parentView.addView(tv); + + parentView.addView(new TextViewBuilder(c, types[i].name) + .align_center() + .size(20) + .build()); views[i] = createEdit(c, types[i]); parentView.addView(views[i]); 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 640903e..85df7da 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 @@ -30,6 +30,7 @@ import com.ridgebotics.ridgescout.types.input.FieldType; import com.ridgebotics.ridgescout.ui.views.CustomSpinnerView; import com.ridgebotics.ridgescout.ui.views.FieldDisplay; import com.ridgebotics.ridgescout.utility.AlertManager; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import java.util.ArrayList; import java.util.Collections; @@ -196,10 +197,9 @@ public class FieldsFragment extends Fragment { sv.addView(table); - TextView UUID = new TextView(getContext()); - UUID.setText("Type: " + field.get_type_name() + "\nUUID: " + field.UUID); - table.addView(UUID); + table.addView(new TextViewBuilder(getContext(), "Type: " + field.get_type_name() + "\nUUID: " + field.UUID) + .build()); FieldEditorHelper f = new FieldEditorHelper(getContext(), field, table); diff --git a/app/src/main/java/com/ridgebotics/ridgescout/ui/settings/SettingsFragment.java b/app/src/main/java/com/ridgebotics/ridgescout/ui/settings/SettingsFragment.java index 87dc742..926d0fe 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/ui/settings/SettingsFragment.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/ui/settings/SettingsFragment.java @@ -54,6 +54,7 @@ import com.ridgebotics.ridgescout.utility.AlertManager; import com.ridgebotics.ridgescout.utility.DataManager; import com.ridgebotics.ridgescout.utility.FileEditor; import com.ridgebotics.ridgescout.utility.ToDelete; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import java.util.ArrayList; import java.util.Arrays; @@ -253,10 +254,8 @@ public class SettingsFragment extends Fragment { private TextView createText(String title) { - TextView tv = new TextView(getContext()); - tv.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Body1); - tv.setText(title); - return tv; + return new TextViewBuilder(getContext(), title) + .body1().build(); } private void showAppInfo() { @@ -395,9 +394,8 @@ public class SettingsFragment extends Fragment { @Override public View createView(Context context) { - TextView titleView = new TextView(context); - titleView.setText(getTitle()); - titleView.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Subtitle1); + TextView titleView = new TextViewBuilder(context, getTitle()) + .sub1().build(); TextInputLayout textInputLayout = new TextInputLayout(context); editText = new TextInputEditText(context); @@ -477,11 +475,10 @@ public class SettingsFragment extends Fragment { }); tally.setEnabled(enabled); - TextView tv = new TextView(getContext()); - tv.setText(getTitle()); - tv.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Headline6); - tv.setGravity(Gravity.CENTER); - ll.addView(tv); + + ll.addView(new TextViewBuilder(getContext(), getTitle()) + .h6() + .build()); ll.addView(tally); @@ -605,10 +602,9 @@ public class SettingsFragment extends Fragment { ll.setOrientation(VERTICAL); ll.setPadding(0, 20,0,0); - TextView tv = new TextView(context); - tv.setText(title); - tv.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Headline4); - ll.addView(tv); + ll.addView(new TextViewBuilder(context, title) + .h4() + .build()); ll.addView(new MaterialDivider(context)); diff --git a/app/src/main/java/com/ridgebotics/ridgescout/ui/transfer/FileSelectorFragment.java b/app/src/main/java/com/ridgebotics/ridgescout/ui/transfer/FileSelectorFragment.java index 1596224..915b335 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/ui/transfer/FileSelectorFragment.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/ui/transfer/FileSelectorFragment.java @@ -24,6 +24,7 @@ import com.ridgebotics.ridgescout.utility.AlertManager; import com.ridgebotics.ridgescout.utility.ByteBuilder; import com.ridgebotics.ridgescout.utility.DataManager; import com.ridgebotics.ridgescout.utility.FileEditor; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import java.util.ArrayList; import java.util.Arrays; @@ -77,10 +78,12 @@ public class FileSelectorFragment extends Fragment { checkBox.setChecked(true); tr.addView(checkBox); - TextView tv = new TextView(getContext()); - tv.setText(String.valueOf(files[i])); - tv.setTextSize(20); - tr.addView(tv); + // Filename + tr.addView( + new TextViewBuilder(getContext(), files[i]) + .size(20) + .build() + ); final int fi = i; tr.setOnClickListener(view -> { diff --git a/app/src/main/java/com/ridgebotics/ridgescout/ui/transfer/TBAEventFragment.java b/app/src/main/java/com/ridgebotics/ridgescout/ui/transfer/TBAEventFragment.java index 72b33eb..9e7b121 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/ui/transfer/TBAEventFragment.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/ui/transfer/TBAEventFragment.java @@ -38,6 +38,7 @@ import com.ridgebotics.ridgescout.utility.JSONUtil; import com.ridgebotics.ridgescout.utility.RequestTask; import com.ridgebotics.ridgescout.utility.FileEditor; import com.ridgebotics.ridgescout.utility.SettingsManager; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import org.json.JSONArray; import org.json.JSONException; @@ -76,23 +77,14 @@ public class TBAEventFragment extends Fragment { Table = binding.matchTable; - Table.setStretchAllColumns(true); - AlertManager.startLoading("Loading Teams and Matches..."); - Table.removeAllViews(); + +// Table.removeAllViews(); Table.setStretchAllColumns(true); Table.bringToFront(); - TableRow tr1 = new TableRow(getContext()); - addTableText(tr1, "Downloading Teams..."); - Table.addView(tr1); - final RequestTask rq = new RequestTask(); rq.onResult(teamsStr -> { - TableRow tr11 = new TableRow(getContext()); - addTableText(tr11, "Downloading Matches..."); - Table.addView(tr11); - final RequestTask rq1 = new RequestTask(); rq1.onResult(matchesStr -> { matchTable(matchesStr, teamsStr, eventData); @@ -108,18 +100,13 @@ public class TBAEventFragment extends Fragment { } private void addTableText(TableRow tr, String textStr){ - TextView text = new TextView(getContext()); - text.setTextSize(18); - text.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); // Text align center - text.setText(textStr); - tr.addView(text); + tr.addView(new TextViewBuilder(getContext(), textStr) + .size(18) +// .align_center() + .build()); } public void matchTable(String matchesString, String teamsString, JSONObject eventData){ - Table.removeAllViews(); - Table.setStretchAllColumns(true); - Table.bringToFront(); - try { final JSONArray matchData = new JSONArray(matchesString); // final JSONArray matchData = new JSONArray(); @@ -134,27 +121,16 @@ public class TBAEventFragment extends Fragment { } // Event code at top - TextView tv = new TextView(getContext()); - tv.setLayoutParams(new TableRow.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setText(matchKey); - tv.setTextSize(18); - Table.addView(tv); + Table.addView(new TextViewBuilder(getContext(), matchKey) + .align_center() + .size(18) + .build()); // Event Name - tv = new TextView(getContext()); - tv.setLayoutParams(new TableRow.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText(matchName); - tv.setTextSize(28); - Table.addView(tv); - - + Table.addView(new TextViewBuilder(getContext(), matchName) + .align_center() + .size(28) + .build()); // Save button MaterialButton btn = new MaterialButton(getContext()); @@ -169,68 +145,42 @@ public class TBAEventFragment extends Fragment { + // If there are no matches, add the error. + // If there are no teams, don't allow the user to save the event and set the button to be invisible if(teamData.length() == 0){ - tv = new TextView(getContext()); - tv.setLayoutParams(new TableRow.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText("This event has no teams released yet..."); - tv.setTextSize(18); - Table.addView(tv); - - tv = new TextView(getContext()); - tv.setLayoutParams(new TableRow.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText("This event has no teams released yet..."); - tv.setTextSize(18); - Table.addView(tv); + Table.addView(new TextViewBuilder(getContext(), "This event has no teams released yet...") + .align_center() + .size(18) + .build()); btn.setVisibility(View.GONE); return; }else if(matchData.length() == 0){ - tv = new TextView(getContext()); - tv.setLayoutParams(new TableRow.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText("This event has no matches released yet..."); - tv.setTextSize(18); - Table.addView(tv); + Table.addView(new TextViewBuilder(getContext(), "This event has no matches released yet...") + .align_center() + .size(18) + .build()); - tv = new TextView(getContext()); - tv.setLayoutParams(new TableRow.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText("Try manually adding practice matches."); - tv.setTextSize(18); - Table.addView(tv); + Table.addView(new TextViewBuilder(getContext(), "Try manually adding practice matches.") + .align_center() + .size(18) + .build()); } - tv = new TextView(getContext()); - tv.setLayoutParams(new TableRow.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText("Teams"); - tv.setTextSize(28); - Table.addView(tv); - + Table.addView( + new TextViewBuilder(getContext(), "Teams") + .align_center() + .size(28) + .build() + ); + // Sort the teams into numerical order int[] teams = new int[teamData.length()]; for(int i = 0 ; i < teamData.length(); i++){ @@ -239,28 +189,26 @@ public class TBAEventFragment extends Fragment { Arrays.sort(teams); + + // Loop through each match TableRow tr = null; for(int i=0; i < teamData.length(); i++){ -// frcTeam team = event.teams.get(i); int num = teams[i]; + // If this is every 7th row, add the new row. if(i % 7 == 0){ if(i != 0) Table.addView(tr); tr = new TableRow(getContext()); } - TextView text = new TextView(getContext()); - text.setTextSize(18); - text.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - text.setText(String.valueOf(num)); -// if(fileEditor.fileExist(event.eventCode + "-" + num + ".pitscoutdata")){ -// text.setBackgroundColor(0x3000FF00); -// }else{ -// text.setBackgroundColor(0x30FF0000); -// } - tr.addView(text); + tr.addView( + new TextViewBuilder(getContext(), String.valueOf(num)) + .align_center() + .size(18) + .build() + ); } if(tr != null) Table.addView(tr); @@ -273,19 +221,13 @@ public class TBAEventFragment extends Fragment { - tv = new TextView(getContext()); - tv.setLayoutParams(new TableRow.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - )); - tv.setGravity(Gravity.CENTER_HORIZONTAL); - tv.setText("Matches"); - tv.setTextSize(28); - Table.addView(tv); - - - - + Table.addView( + new TextViewBuilder(getContext(), "Matches") + .align_center() + .size(28) + .build() + ); + tr = new TableRow(getContext()); addTableText(tr, "#"); addTableText(tr, "Red-1"); @@ -339,22 +281,24 @@ public class TBAEventFragment extends Fragment { int[] redKeys = new int[3]; for(int b=0;b<6;b++){ - TextView text = new TextView(getContext()); - text.setTextSize(18); - text.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); // Text align center - tr.addView(text); + TextViewBuilder text = new TextViewBuilder(getContext()) + .size(18) + .align_center(); if(b < 3){ String str = redAlliance.getString(b).substring(3); redKeys[b] = Integer.parseInt(str); - text.setText(str); - text.setBackgroundColor(tba_red); + text.text(str); + text.tv.setBackgroundColor(tba_red); }else{ String str = blueAlliance.getString(b-3).substring(3); blueKeys[b-3] = Integer.parseInt(str); - text.setText(str); - text.setBackgroundColor(tba_blue); + text.text(str); + text.tv.setBackgroundColor(tba_blue); } + + + tr.addView(text.build()); } Table.addView(tr); @@ -369,14 +313,6 @@ public class TBAEventFragment extends Fragment { toggle = !toggle; } -// btn.setOnClickListener(v -> { -// if(saveData(matchesOBJ, teamData, eventData)){ -// alert("Info", "Saved!"); -// }else{ -// alert("Error", "Error saving files."); -// } -// }); - }catch (JSONException j){ AlertManager.error("Failed Downloading", j); AlertManager.stopLoading(); @@ -384,7 +320,7 @@ public class TBAEventFragment extends Fragment { } private boolean saveData(ArrayList matchData, JSONArray teamData, JSONObject eventData){ - AlertManager.startLoading("Saving data..."); + AlertManager.startLoading("Downloading team data..."); Thread t = new Thread(() -> { try { 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 6bed0ba..15c5918 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 @@ -25,6 +25,7 @@ import com.ridgebotics.ridgescout.ui.views.TBAEventOption; import com.ridgebotics.ridgescout.utility.AlertManager; import com.ridgebotics.ridgescout.utility.RequestTask; import com.ridgebotics.ridgescout.utility.SettingsManager; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import org.json.JSONArray; import org.json.JSONException; @@ -54,12 +55,6 @@ public class TBASelectorFragment extends Fragment { Table = binding.matchTable; - Table.setStretchAllColumns(true); - - TableRow tr = new TableRow(getContext()); - addTableText(tr, "Loading Events..."); - Table.addView(tr); - startLoading("Loading Events..."); final RequestTask rq = new RequestTask(); @@ -77,14 +72,6 @@ public class TBASelectorFragment extends Fragment { return binding.getRoot(); } - private void addTableText(TableRow tr, String textStr){ - TextView text = new TextView(getContext()); - text.setTextSize(18); - text.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); // Text align center - text.setText(textStr); - tr.addView(text); - } - public static int getEventTypeWeight(String type){ switch(type){ case "Preseason": return -3; @@ -103,7 +90,7 @@ public class TBASelectorFragment extends Fragment { public void eventTable(String dataString){ Table.removeAllViews(); - Table.setStretchAllColumns(true); +// Table.setStretchAllColumns(true); Table.bringToFront(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); diff --git a/app/src/main/java/com/ridgebotics/ridgescout/utility/ToDelete.java b/app/src/main/java/com/ridgebotics/ridgescout/utility/ToDelete.java index 2822677..7e68437 100644 --- a/app/src/main/java/com/ridgebotics/ridgescout/utility/ToDelete.java +++ b/app/src/main/java/com/ridgebotics/ridgescout/utility/ToDelete.java @@ -11,6 +11,7 @@ import android.widget.ScrollView; import android.widget.TextView; import com.ridgebotics.ridgescout.types.ColabArray; +import com.ridgebotics.ridgescout.utility.builders.TextViewBuilder; import java.util.ArrayList; import java.util.List; @@ -60,9 +61,7 @@ public class ToDelete { AlertDialog.Builder confirm = new AlertDialog.Builder(c); alert.setTitle("Confirm"); - TextView tv = new TextView(c); - tv.setText("Are you sure you want to delete " + delete_files.size() + " files?"); - alert.setView(tv); + alert.setView(new TextViewBuilder(c, "Are you sure you want to delete " + delete_files.size() + " files?").build()); alert.setNeutralButton("Cancel", null); alert.setPositiveButton("Delete", (dialogInterface, i) -> { deleteFiles(delete_files); diff --git a/app/src/main/java/com/ridgebotics/ridgescout/utility/builders/TextViewBuilder.java b/app/src/main/java/com/ridgebotics/ridgescout/utility/builders/TextViewBuilder.java new file mode 100644 index 0000000..cf18e75 --- /dev/null +++ b/app/src/main/java/com/ridgebotics/ridgescout/utility/builders/TextViewBuilder.java @@ -0,0 +1,161 @@ +package com.ridgebotics.ridgescout.utility.builders; + +import android.content.Context; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import android.widget.TableRow; +import android.widget.TextView; + +public class TextViewBuilder { + public TextView tv; + public TextViewBuilder(Context c) { + tv = new TextView(c); + } + + public TextViewBuilder(Context c, String str) { + tv = new TextView(c); + tv.setText(str); + } + + public TextViewBuilder size(float size) { + tv.setTextSize(size); + return this; + } + + public TextViewBuilder text(String str) { + tv.setText(str); + return this; + } + + public TextViewBuilder padding(int borders) { + tv.setPadding(borders,borders,borders,borders); + return this; + } + + public TextViewBuilder padding(int horisontal, int vertical) { + tv.setPadding(horisontal,vertical,horisontal,vertical); + return this; + } + + public TextViewBuilder padding(int left, int right, int top, int bottom) { + tv.setPadding(left,top,right,bottom); + return this; + } + + public TextViewBuilder align_left() { + tv.setGravity(Gravity.START); + tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); + return this; + } + + public TextViewBuilder align_center() { + tv.setGravity(Gravity.CENTER_HORIZONTAL); +// FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( +// ViewGroup.LayoutParams.MATCH_PARENT, +// ViewGroup.LayoutParams.WRAP_CONTENT +// ); +// params.gravity = Gravity.CENTER; +// tv.setLayoutParams(params); +// +// + tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); + return this; + } + + + +// public TextViewBuilder center_xy() { +// TableRow.LayoutParams params = new TableRow.LayoutParams(); +// params.gravity = Gravity.CENTER; +// tv.setLayoutParams(params); +// return this; +// } + + public TextViewBuilder align_right() { + tv.setGravity(Gravity.END); + tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_END); + return this; + } + + public TextViewBuilder layout_wrap_wrap() { + tv.setLayoutParams(new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT + )); + return this; + } + + public TextViewBuilder layout_wrap_match() { + tv.setLayoutParams(new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.MATCH_PARENT + )); + return this; + } + + public TextViewBuilder layout_match_wrap() { + tv.setLayoutParams(new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + )); + return this; + } + + public TextViewBuilder layout_match_match() { + tv.setLayoutParams(new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + )); + return this; + } + + public TextViewBuilder h1() { + tv.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Headline1); + return this; + } + public TextViewBuilder h2() { + tv.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Headline2); + return this; + } + public TextViewBuilder h3() { + tv.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Headline3); + return this; + } + public TextViewBuilder h4() { + tv.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Headline4); + return this; + } + public TextViewBuilder h5() { + tv.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Headline5); + return this; + } + public TextViewBuilder h6() { + tv.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Headline6); + return this; + } + + public TextViewBuilder sub1() { + tv.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Subtitle1); + return this; + } + public TextViewBuilder sub2() { + tv.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Subtitle2); + return this; + } + + public TextViewBuilder body1() { + tv.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Body1); + return this; + } + public TextViewBuilder body2() { + tv.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Body2); + return this; + } + + + public TextView build() { + return tv; + } +}