diff --git a/ScoutingApp/app/src/main/AndroidManifest.xml b/ScoutingApp/app/src/main/AndroidManifest.xml index 9252612..10219a2 100644 --- a/ScoutingApp/app/src/main/AndroidManifest.xml +++ b/ScoutingApp/app/src/main/AndroidManifest.xml @@ -1,48 +1,48 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ScoutingApp/app/src/main/java/com/example/scoutingapp/Submit.java b/ScoutingApp/app/src/main/java/com/example/scoutingapp/Submit.java index 1b531e9..fbd299b 100644 --- a/ScoutingApp/app/src/main/java/com/example/scoutingapp/Submit.java +++ b/ScoutingApp/app/src/main/java/com/example/scoutingapp/Submit.java @@ -1,168 +1,168 @@ -package com.example.scoutingapp; - -import android.content.Context; -import android.content.SharedPreferences; -import android.content.Intent; -import android.content.SharedPreferences; -import android.net.ConnectivityManager; -import android.net.NetworkCapabilities; -import android.net.NetworkInfo; -import android.os.Build; -import android.util.Log; -import android.widget.Toast; - -import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; -import com.google.api.client.json.gson.GsonFactory; -import com.google.api.services.sheets.v4.Sheets; -import com.google.api.services.sheets.v4.model.ValueRange; -import com.google.auth.http.HttpCredentialsAdapter; -import com.google.auth.oauth2.ServiceAccountCredentials; -import com.google.common.collect.Lists; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; -import java.util.List; - -public class Submit { - public static SharedPreferences getPrefs(Context context) { - return context.getSharedPreferences("MySettings", Context.MODE_PRIVATE); - } - - - - void uploadSheets(Context context, String csvFileString) { - SharedPreferences sharedPreferences = getPrefs(context); - String savedText = sharedPreferences.getString("SheetsText", ""); - new Thread(() -> { - try { - //adds account info - InputStream serviceAccountStream = context.getResources().openRawResource(R.raw.info); - ServiceAccountCredentials credentials = ServiceAccountCredentials.fromStream(serviceAccountStream); - //Sets up the google sheet API and json factory for use later - Sheets sheetsService = new Sheets.Builder( - GoogleNetHttpTransport.newTrustedTransport(), - GsonFactory.getDefaultInstance(), - new HttpCredentialsAdapter(credentials) - ).setApplicationName("Scouting App").build(); - - //make sure the file is there - File csvFile = new File(context.getFilesDir(), csvFileString); - if (!csvFile.exists()) { - Log.d("CSVError", "CSV file does not exist."); - return; - } - //uses parseCSVToList make the CSV file into a list for google sheet - List> data = parseCSVToList(csvFile); - //data for the sheet API - ValueRange body = new ValueRange().setValues(data); - //the ID for the google sheet - String spreadsheetId = savedText; - //starting point - String range = "Data!a2:O2"; - //inserts data to the sheet - sheetsService.spreadsheets().values() - .append(spreadsheetId, range, body) - .setValueInputOption("USER_ENTERED") - .setInsertDataOption("INSERT_ROWS") - .execute(); - - Log.e("GoogleSheets", "Data uploaded to Google Sheets successfully."); - deleteCSVFile(context, csvFileString); - } catch (Exception e) { - Log.e("GoogleSheetFailed", "Failed to upload", e); - } - }).start(); - } - - List> parseCSVToList(File csvFile) { - List> data = Lists.newArrayList(); - try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) { - String line; - while ((line = br.readLine()) != null) { - String[] values = line.split("@#@"); // Assuming CSV is comma-separated - data.add(Arrays.asList((Object[]) values)); - } - } catch (IOException e) { - Log.d("CSVError", "Error reading CSV file", e); - } - return data; - } - - - public void deleteCSVFile(Context context, String csvFileString) { - // Get the directory containing the files - File directory = context.getFilesDir(); - - // Get all files in the directory - File[] files = directory.listFiles(); - - if (files != null) { - for (File file : files) { - // Check if the file name matches the given string - if (file.getName().equals(csvFileString)) { - if (file.delete()) { - Log.d("CSVDelete", file.getName() + " deleted successfully."); - } else { - Log.d("CSVDelete", "Failed to delete " + file.getName()); - } - return; // Exit after deleting the file - } - } - Log.d("CSVDelete", "File " + csvFileString + " not found."); - } else { - Log.d("CSVDelete", "No files found in the directory."); - } - } - - - public void renameFile(Context context, String csvFileString) { - File csvFile = new File(context.getFilesDir(), csvFileString); - - if (!csvFile.exists()) { - Log.d("CSVRenameFail", "File does not exist: " + csvFile.getAbsolutePath()); - return; - } - - File renamedFile = new File(context.getFilesDir(), csvFileString); - - if (csvFile.renameTo(renamedFile)) { - Log.d("CSVRename", "File renamed successfully to: " + renamedFile.getAbsolutePath()); - } else { - Log.d("CSVRenameFail", "File renaming failed. Possible reasons: file is in use, permission issue, or incorrect file path."); - } - } - - public void renameFileagain(Context context, String csvFileString) { - File csvFile = new File(context.getFilesDir(), csvFileString); - - if (!csvFile.exists()) { - Log.d("CSVRenameFail", "File does not exist: " + csvFile.getAbsolutePath()); - return; - } - - File renamedFile = new File(context.getFilesDir(), "uploaded.csv"); - - if (csvFile.renameTo(renamedFile)) { - Log.d("CSVRename", "File renamed successfully to: " + renamedFile.getAbsolutePath()); - } else { - Log.d("CSVRenameFail", "File renaming failed. Possible reasons: file is in use, permission issue, or incorrect file path."); - } - } - - public boolean isWifiConnected(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - - if (cm != null) { - android.net.Network network = cm.getActiveNetwork(); - if (network == null) return false; - NetworkCapabilities capabilities = cm.getNetworkCapabilities(network); - return capabilities != null && capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI); - } - return false; - } +package com.example.scoutingapp; + +import android.content.Context; +import android.content.SharedPreferences; +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.ConnectivityManager; +import android.net.NetworkCapabilities; +import android.net.NetworkInfo; +import android.os.Build; +import android.util.Log; +import android.widget.Toast; + +import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; +import com.google.api.client.json.gson.GsonFactory; +import com.google.api.services.sheets.v4.Sheets; +import com.google.api.services.sheets.v4.model.ValueRange; +import com.google.auth.http.HttpCredentialsAdapter; +import com.google.auth.oauth2.ServiceAccountCredentials; +import com.google.common.collect.Lists; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; + +public class Submit { + public static SharedPreferences getPrefs(Context context) { + return context.getSharedPreferences("MySettings", Context.MODE_PRIVATE); + } + + + + void uploadSheets(Context context, String csvFileString) { + SharedPreferences sharedPreferences = getPrefs(context); + String savedText = sharedPreferences.getString("SheetsText", ""); + new Thread(() -> { + try { + //adds account info + InputStream serviceAccountStream = context.getResources().openRawResource(R.raw.info); + ServiceAccountCredentials credentials = ServiceAccountCredentials.fromStream(serviceAccountStream); + //Sets up the google sheet API and json factory for use later + Sheets sheetsService = new Sheets.Builder( + GoogleNetHttpTransport.newTrustedTransport(), + GsonFactory.getDefaultInstance(), + new HttpCredentialsAdapter(credentials) + ).setApplicationName("Scouting App").build(); + + //make sure the file is there + File csvFile = new File(context.getFilesDir(), csvFileString); + if (!csvFile.exists()) { + Log.d("CSVError", "CSV file does not exist."); + return; + } + //uses parseCSVToList make the CSV file into a list for google sheet + List> data = parseCSVToList(csvFile); + //data for the sheet API + ValueRange body = new ValueRange().setValues(data); + //the ID for the google sheet + String spreadsheetId = savedText; + //starting point + String range = "Data!a2:O2"; + //inserts data to the sheet + sheetsService.spreadsheets().values() + .append(spreadsheetId, range, body) + .setValueInputOption("USER_ENTERED") + .setInsertDataOption("INSERT_ROWS") + .execute(); + + Log.e("GoogleSheets", "Data uploaded to Google Sheets successfully."); + deleteCSVFile(context, csvFileString); + } catch (Exception e) { + Log.e("GoogleSheetFailed", "Failed to upload", e); + } + }).start(); + } + + List> parseCSVToList(File csvFile) { + List> data = Lists.newArrayList(); + try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) { + String line; + while ((line = br.readLine()) != null) { + String[] values = line.split("@#@"); // Assuming CSV is comma-separated + data.add(Arrays.asList((Object[]) values)); + } + } catch (IOException e) { + Log.d("CSVError", "Error reading CSV file", e); + } + return data; + } + + + public void deleteCSVFile(Context context, String csvFileString) { + // Get the directory containing the files + File directory = context.getFilesDir(); + + // Get all files in the directory + File[] files = directory.listFiles(); + + if (files != null) { + for (File file : files) { + // Check if the file name matches the given string + if (file.getName().equals(csvFileString)) { + if (file.delete()) { + Log.d("CSVDelete", file.getName() + " deleted successfully."); + } else { + Log.d("CSVDelete", "Failed to delete " + file.getName()); + } + return; // Exit after deleting the file + } + } + Log.d("CSVDelete", "File " + csvFileString + " not found."); + } else { + Log.d("CSVDelete", "No files found in the directory."); + } + } + + + public void renameFile(Context context, String csvFileString) { + File csvFile = new File(context.getFilesDir(), csvFileString); + + if (!csvFile.exists()) { + Log.d("CSVRenameFail", "File does not exist: " + csvFile.getAbsolutePath()); + return; + } + + File renamedFile = new File(context.getFilesDir(), csvFileString); + + if (csvFile.renameTo(renamedFile)) { + Log.d("CSVRename", "File renamed successfully to: " + renamedFile.getAbsolutePath()); + } else { + Log.d("CSVRenameFail", "File renaming failed. Possible reasons: file is in use, permission issue, or incorrect file path."); + } + } + + public void renameFileagain(Context context, String csvFileString) { + File csvFile = new File(context.getFilesDir(), csvFileString); + + if (!csvFile.exists()) { + Log.d("CSVRenameFail", "File does not exist: " + csvFile.getAbsolutePath()); + return; + } + + File renamedFile = new File(context.getFilesDir(), "uploaded.csv"); + + if (csvFile.renameTo(renamedFile)) { + Log.d("CSVRename", "File renamed successfully to: " + renamedFile.getAbsolutePath()); + } else { + Log.d("CSVRenameFail", "File renaming failed. Possible reasons: file is in use, permission issue, or incorrect file path."); + } + } + + public boolean isWifiConnected(Context context) { + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + + if (cm != null) { + android.net.Network network = cm.getActiveNetwork(); + if (network == null) return false; + NetworkCapabilities capabilities = cm.getNetworkCapabilities(network); + return capabilities != null && capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI); + } + return false; + } } \ No newline at end of file diff --git a/ScoutingApp/gradle/wrapper/gradle-wrapper.properties b/ScoutingApp/gradle/wrapper/gradle-wrapper.properties index 8ee2dde..64d723c 100644 --- a/ScoutingApp/gradle/wrapper/gradle-wrapper.properties +++ b/ScoutingApp/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Jan 06 12:48:44 EST 2025 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +#Mon Jan 06 12:48:44 EST 2025 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/ScoutingApp/gradlew.bat b/ScoutingApp/gradlew.bat index ac1b06f..107acd3 100644 --- a/ScoutingApp/gradlew.bat +++ b/ScoutingApp/gradlew.bat @@ -1,89 +1,89 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega