Made the submit button make a CSV file

This commit is contained in:
wildercayden 2025-01-14 14:41:08 -05:00 committed by GitHub
parent 54bd17a079
commit aeb6942202
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,11 @@
package com.example.scoutingapp; package com.example.scoutingapp;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.activity.EdgeToEdge; import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -8,7 +13,15 @@ import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat; import androidx.core.view.WindowInsetsCompat;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Arrays;
public class EndActivity extends AppCompatActivity { public class EndActivity extends AppCompatActivity {
private String teamNumber, matchNumber, Taxiing, autoCoral, autoAlgea, floorPickup, HPPickup, startingLocation, teleopCoral, teleopAlgea, HPScore, teleopFloorPickup, Endgame, Climb, Notes;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -20,5 +33,38 @@ public class EndActivity extends AppCompatActivity {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets; return insets;
}); });
Button submit = (Button) findViewById(R.id.Submit_button);
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
CSVmake(EndActivity.this);
}
});
}
public String getTeamNumber() {
teamNumber = "hello world";
return teamNumber;
}
public void CSVmake(Context context) {
String CSVLine = teamNumber + "," + matchNumber + "," + Taxiing + "," + autoCoral + "," +
autoAlgea + "," + floorPickup + "," + HPPickup + "," + startingLocation + "," +
teleopCoral + "," + teleopAlgea + "," + HPScore + "," + teleopFloorPickup + "," +
Endgame + "," + Climb + "," + Notes; //adds the strings the CSV file (if the strings have info)
File csvFile = new File(context.getExternalFilesDir(null), "match_data.csv");//makes the CSV file
try (FileWriter writer = new FileWriter(csvFile, true)) {//writes data to the file from CSVLine
writer.append(CSVLine).append("\n");
Log.d("CSVFilePath", csvFile.getAbsolutePath());
} catch (IOException e) { //if it doesn't work it makes a toast and a log to tell you it didn't work
Log.d("CSVFail", "CSV didn't make");
Toast.makeText(this /* MyActivity */, "Failed to make server", Toast.LENGTH_SHORT).show();
};
} }
} }