commit 2e142b56b75b876a6cf75129593fbb93f0313b75 Author: ncgears <1918ncgears@gmail.com> Date: Tue Apr 23 18:39:21 2024 -0400 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..21c2028 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# ScoutingBase +Base Project for NC GEARS Scouting app diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..be55868 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1,59 @@ +#built application files +*.apk +*.ap_ + +# files for the dex VM +*.dex + +# Java class files +*.class + +# generated files +bin/ +gen/ + +# Local configuration file (sdk path, etc) +local.properties + +# Windows thumbnail db +Thumbs.db + +# OSX files +.DS_Store + +# Android Studio +*.iml +.idea +#.idea/workspace.xml - remove # and delete .idea if it better suit your needs. +.gradle +build/ +.navigation +captures/ +output.json + +#NDK +obj/ +.externalNativeBuild +Since Android Studio 2.2 and up to 3.0, new projects are created with this gitignore file: + +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild +Deprecated - for older project format, add this section to your gitignore file: + + +/*/out +/*/*/build +/*/*/production +*.iws +*.ipr +*~ +*.swp + +Settings.java \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..4b5e6a2 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,35 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + defaultConfig { + applicationId "com.example.vande.scouting2018" + minSdkVersion 17 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + namespace 'com.example.ncgears.scouting' +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + implementation 'com.jakewharton:butterknife:8.7.0' + annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0' + implementation 'com.android.support:design:26.1.0' + testImplementation 'junit:junit:4.12' + implementation files('libs/javacsv.jar') + +} diff --git a/app/libs/javacsv.jar b/app/libs/javacsv.jar new file mode 100644 index 0000000..84e3353 Binary files /dev/null and b/app/libs/javacsv.jar differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..136e284 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png new file mode 100644 index 0000000..1c1f32f Binary files /dev/null and b/app/src/main/ic_launcher-web.png differ diff --git a/app/src/main/java/com/example/ncgears/scouting/AutonActivity.java b/app/src/main/java/com/example/ncgears/scouting/AutonActivity.java new file mode 100644 index 0000000..c81bdcf --- /dev/null +++ b/app/src/main/java/com/example/ncgears/scouting/AutonActivity.java @@ -0,0 +1,525 @@ +/* + + *************** Code Designed by Team 107 Team Robotics ********************* + *************** Edited for Team 1918 By Nate and Ken ********************* + + + */ + +package com.example.ncgears.scouting; + +import android.Manifest; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.database.sqlite.SQLiteDatabase; +import android.graphics.Color; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.design.widget.TextInputEditText; +import android.support.design.widget.TextInputLayout; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.ncgears.scouting.data.TeamsDbHelper; + +import java.util.ArrayList; + +import butterknife.BindView; +import butterknife.ButterKnife; +import utils.FormatStringUtils; +import utils.StringUtils; +import utils.ViewUtils; + +public class AutonActivity extends AppCompatActivity implements View.OnKeyListener { + + /*This area sets and binds all of the variables that we will use in the auton activity*/ + public static String AUTON_STRING_EXTRA = "auton_extra"; + + /* These are the names of the match number and team number extras that will be passed into teleop */ + public static final String MATCH_STRING_EXTRA = "match_extra"; + public static final String TEAMNUMBER_STRING_EXTRA = "teamnumber_extra"; + + + @BindView(R.id.team_number_spinner) + public Spinner TeamNumberInputLayout; + + @BindView(R.id.auto_high_attempt_input_layout) + public TextInputLayout AutoHighAttemptInputLayout; + + @BindView(R.id.auto_high_attempt_input) + public TextInputEditText AutoHighAttemptInput; + + @BindView(R.id.auto_high_made_layout) + public TextInputLayout AutoHighMadeLayout; + + @BindView(R.id.auto_high_made_input) + public TextInputEditText AutoHighMadeInput; + + @BindView(R.id.auto_low_attempt_input_layout) + public TextInputLayout AutoLowAttemptInputLayout; + + @BindView(R.id.auto_low_attempt_input) + public TextInputEditText AutoLowAttemptInput; + + @BindView(R.id.auto_low_made_layout) + public TextInputLayout AutoLowMadeLayout; + + @BindView(R.id.auto_low_made_input) + public TextInputEditText AutoLowMadeInput; + + //Trap Starts + @BindView(R.id.auto_trap_attempt_input_layout) + public TextInputLayout AutoTrapAttemptInputLayout; + + @BindView(R.id.auto_trap_attempt_input) + public TextInputEditText AutoTrapAttemptInput; + + @BindView(R.id.auto_trap_made_layout) + public TextInputLayout AutoTrapMadeLayout; + + @BindView(R.id.auto_trap_made_input) + public TextInputEditText AutoTrapMadeInput; + //Trap Ends + @BindView(R.id.matchNumber_input_layout) + public TextInputLayout matchNumberInputLayout; + + @BindView(R.id.matchNumber_input) + public EditText matchNumberInput; + + @BindView(R.id.starting_location) + public Spinner startingLocation; + + @BindView(R.id.auto_initiation_line) + RadioGroup autoInitiationLine; + + @BindView(R.id.next_button) + public Button nextButton; + + int HighAttempt = 0; + int HighMissed =0; + int HighMade = 0; + int LowAttempt = 0; + int LowMissed = 0; + int LowMade = 0; + int TrapAttempt = 0; + int TrapMade = 0; + int TrapMissed = 0; + + public ArrayList team_numbers = new ArrayList<>(); + private ArrayList autonDataStringList; + public static final int REQUEST_CODE = 1; + + + /*When this activity is first called, + *we will call the activity_auton layout so we can display + *the user interface + */ + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + TeamsDbHelper mDbHelper = new TeamsDbHelper(this); + SQLiteDatabase db = mDbHelper.getReadableDatabase(); + + setContentView(R.layout.activity_auton); + ButterKnife.bind(this); + autonDataStringList = new ArrayList<>(); + team_numbers = TeamsDbHelper.getTeamNumbers(db); + + checkForPermissions(); + + AutoHighAttemptInput.setText("" + HighMissed); + AutoHighMadeInput.setText("" + HighMade); + AutoLowAttemptInput.setText("" + LowMissed); + AutoLowMadeInput.setText("" + LowMade); + AutoTrapAttemptInput.setText("" + TrapMissed); + AutoTrapMadeInput.setText("" + TrapMade); + + + // --- Team Numbers spinner --- + + Spinner teamnumberspinner = (Spinner) findViewById(R.id.team_number_spinner); +// Create an ArrayAdapter using the string array and a default spinner layout + ArrayAdapter teamnumberadapter = new ArrayAdapter(AutonActivity.this, + android.R.layout.simple_spinner_dropdown_item, team_numbers); +// Specify the layout to use when the list of choices appears + teamnumberadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); +// Apply the adapter to the spinner + teamnumberspinner.setAdapter(teamnumberadapter); + + + } + + /*If this activity is resumed from a paused state the data + *will be set to what they previously were set to + */ + @Override + protected void onResume() { + super.onResume(); + + autonDataStringList.clear(); + + TeamNumberInputLayout.setOnKeyListener(this); + AutoHighAttemptInputLayout.setOnKeyListener(this); + AutoHighMadeLayout.setOnKeyListener(this); + AutoLowAttemptInputLayout.setOnKeyListener(this); + AutoLowMadeLayout.setOnKeyListener(this); + AutoTrapAttemptInputLayout.setOnKeyListener(this); + AutoTrapMadeLayout.setOnKeyListener(this); + matchNumberInput.setOnKeyListener(this); + startingLocation.setOnKeyListener(this); + + + } + + /*If this activity enters a paused state the data will be set to null*/ + @Override + protected void onPause() { + super.onPause(); + + TeamNumberInputLayout.setOnKeyListener(null); + AutoHighAttemptInputLayout.setOnKeyListener(null); + AutoHighMadeLayout.setOnKeyListener(null); + AutoLowAttemptInputLayout.setOnKeyListener(null); + AutoLowMadeLayout.setOnKeyListener(null); + AutoTrapAttemptInputLayout.setOnKeyListener(null); + AutoTrapMadeLayout.setOnKeyListener(null); + matchNumberInput.setOnKeyListener(null); + startingLocation.setOnKeyListener(null); + + } + + /* This method will display the options menu when the icon is pressed + * and this will inflate the menu options for the user to choose + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main_menu, menu); + return true; + } + + /*This method will launch the correct activity + *based on the menu option user presses + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.main_activity: + startActivity(new Intent(this, MainActivity.class)); + return true; + case R.id.send_data: + startActivity(new Intent(this, SendDataActivity.class)); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + + /*This method will look at all of the text/number input fields and set error + *for validation of data entry + */ + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { + if (keyCode != KeyEvent.KEYCODE_SPACE && keyCode != KeyEvent.KEYCODE_TAB) { + TextInputEditText inputEditText = (TextInputEditText) v; + + if (inputEditText != null) { + + switch (inputEditText.getId()) { + + + case R.id.matchNumber_input: + matchNumberInputLayout.setError(null); + break; + } + } + } + return false; + } + + + /*This method takes place when the Show teleop button is pressed + *This will first check if the text fields are empty and highlight + * The area not completed as well as put that text input as the focus + * to the user in the app. If everything passes by being filled in, + * The value of the radio buttons will be obtained. + * Then all of the values of this activity are added to the autonDataStringList + * delimited by a comma. This method will then launch the teleop activity while sending + * over our list of data. A request on result is requested so we can clear this aplication + * after the teleop activity closes + */ + public void onShowTeleop(View view) { + boolean allInputsPassed = false; + + final RadioButton autoInitiationLineRadioBtn = findViewById(autoInitiationLine.getCheckedRadioButtonId()); + + if (TeamNumberInputLayout.getSelectedItem().toString().equals("Select Team Number")) { + setSpinnerError(TeamNumberInputLayout, "Select a Team Number."); + ViewUtils.requestFocus(TeamNumberInputLayout, this); + } else if (StringUtils.isEmptyOrNull(getTextInputLayoutString(matchNumberInputLayout)) || Integer.valueOf(getTextInputLayoutString(matchNumberInputLayout)) == 0 || Integer.valueOf(getTextInputLayoutString(matchNumberInputLayout)) >= 150) { + matchNumberInput.setText(""); + matchNumberInputLayout.setError(getText(R.string.matchNumberError)); + ViewUtils.requestFocus(matchNumberInputLayout, this); + } else { + allInputsPassed = true; + } + + if (!allInputsPassed) { + return; + } + + autonDataStringList.add(TeamNumberInputLayout.getSelectedItem().toString()); + autonDataStringList.add(getTextInputLayoutString(matchNumberInputLayout)); +// autonDataStringList.add(startingLocation.getSelectedItem().toString()); + autonDataStringList.add(getTextInputLayoutString(AutoHighAttemptInputLayout)); + autonDataStringList.add(getTextInputLayoutString(AutoHighMadeLayout)); + autonDataStringList.add(getTextInputLayoutString(AutoLowAttemptInputLayout)); + autonDataStringList.add(getTextInputLayoutString(AutoLowMadeLayout)); + autonDataStringList.add(getTextInputLayoutString(AutoTrapAttemptInputLayout)); + autonDataStringList.add(getTextInputLayoutString(AutoTrapMadeLayout)); + autonDataStringList.add(autoInitiationLineRadioBtn.getText().toString()); + + + + + //autonDataStringList.add(playStyle.getSelectedItem().toString()); + + final Intent intent = new Intent(this, TeleopActivity.class); + intent.putExtra(AUTON_STRING_EXTRA, FormatStringUtils.addDelimiter(autonDataStringList, "|")); + intent.putExtra(MATCH_STRING_EXTRA, getTextInputLayoutString(matchNumberInputLayout)); + intent.putExtra(TEAMNUMBER_STRING_EXTRA, TeamNumberInputLayout.getSelectedItem().toString()); + + startActivityForResult(intent, REQUEST_CODE); + + + matchNumberInputLayout.setError(null); + + matchNumberInput.requestFocus(); + + } + + + /*This method will check for the result code from the teleop activity + *so we can clear the data before the next match scouting starts + */ + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + try { + super.onActivityResult(requestCode, resultCode, data); + + if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { + clearData(); + finish(); + } + } catch (Exception ex) { + Toast.makeText(this, ex.toString(), Toast.LENGTH_SHORT).show(); + } + } + + /*This method will clear all of the text entry fields as well + * as reset the checkboxes and reset the radio buttons to their default*/ + public void clearData() { + TeamNumberInputLayout.setSelection(0); + matchNumberInput.setText(""); + startingLocation.setSelection(0); + AutoHighAttemptInput.setText("" + HighMissed); + AutoHighMadeInput.setText("" + HighMade); + AutoLowAttemptInput.setText("" + LowMissed); + AutoLowMadeInput.setText("" + LowMade); + AutoTrapAttemptInput.setText("" + TrapAttempt); + AutoTrapMadeInput.setText("" + TrapMade); + HighAttempt = 0; + HighMissed =0; + HighMade = 0; + LowAttempt = 0; + LowMissed = 0; + LowMade = 0; + TrapAttempt = 0; + TrapMissed = 0; + TrapMade = 0; + autoInitiationLine.check(R.id.AutoInitiationLine_yes); + displayAutoHighAttemptInput(HighMissed); + displayAutoHighMadeInput(HighMade); + displayAutoLowAttemptInput(LowMissed); + displayAutoLowMadeInput(LowMade); + + + } + + + private void setSpinnerError(Spinner spinner, String error) { + View selectedView = spinner.getSelectedView(); + if (selectedView instanceof TextView) { + spinner.requestFocus(); + TextView selectedTextView = (TextView) selectedView; + selectedTextView.setError("error"); + selectedTextView.setTextColor(Color.RED); + selectedTextView.setText(error); + + } + } + + + /* This method will change the text entered into the app into a string if it is not already*/ + private String getTextInputLayoutString(@NonNull TextInputLayout textInputLayout) { + final EditText editText = textInputLayout.getEditText(); + return editText != null && editText.getText() != null ? editText.getText().toString() : ""; + } + + private void checkForPermissions() { + int writePermission = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE); + + if (writePermission != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); + } + } + + public void decreaseAutoHighAttemptInput(View view) { + if (HighMissed != 0) { + HighMissed -= 1; + HighAttempt -=1; + + displayAutoHighAttemptInput(HighMissed); + + } + } + + public void increaseAutoHighAttemptInput(View view) { + if (HighMissed <= 800) { + HighMissed += 1; + HighAttempt +=1; + displayAutoHighAttemptInput(HighMissed); + } + + } + + private void displayAutoHighAttemptInput(int number) { + + AutoHighAttemptInput.setText("" + number); + } + + public void decreaseAutoHighMadeInput(View view) { + if (HighMade != 0) { + HighMade -= 1; + HighAttempt -= 1; + displayAutoHighMadeInput(HighMade); + } + } + + public void increaseAutoHightMadeInput(View view) { + if (HighMade <= 800) { + HighMade +=1; + HighAttempt += 1; + displayAutoHighMadeInput(HighMade); + } + + } + + private void displayAutoHighMadeInput(int number) { + + AutoHighMadeInput.setText("" + number); + } + + public void decreaseAutoLowAttemptInput(View view) { + if (LowMissed != 0) { + LowMissed -= 1; + LowAttempt -=1; + + displayAutoLowAttemptInput(LowMissed); + } + } + + public void increaseAutoLowAttemptInput(View view) { + if (LowMissed <= 800) { + LowMissed += 1; + LowAttempt += 1; + displayAutoLowAttemptInput(LowMissed); + } + + } + + private void displayAutoLowAttemptInput(int number) { + + AutoLowAttemptInput.setText("" + number); + } + + public void decreaseAutoLowMadeInput(View view) { + if (LowMade != 0) { + LowMade -= 1; + LowAttempt -=1; + displayAutoLowMadeInput(LowMade); + } + } + + public void increaseAutoLowMadeInput(View view) { + if (LowMade <= 800) { + LowMade += 1; + LowAttempt +=1; + displayAutoLowMadeInput(LowMade); + + } + + } + + private void displayAutoLowMadeInput(int number) { + + AutoLowMadeInput.setText("" + number); + } + public void decreaseAutoTrapAttemptInput(View view) { + if (TrapMissed != 0) { + TrapMissed -= 1; + TrapAttempt -=1; + + displayAutoTrapAttemptInput(TrapMissed); + } + } + public void increaseAutoTrapAttemptInput(View view) { + if (TrapMissed <= 800) { + TrapMissed += 1; + TrapAttempt += 1; + displayAutoTrapAttemptInput(TrapMissed); + } + + } + + public void decreaseAutoTrapMadeInput(View view) { + if (TrapMade != 0) { + TrapMade -= 1; + TrapAttempt -=1; + displayAutoTrapMadeInput(TrapMade); + } + } + + public void increaseAutoTrapMadeInput(View view) { + if (TrapMade <= 800) { + TrapMade += 1; + TrapAttempt +=1; + displayAutoTrapMadeInput(TrapMade); + + } + + } + private void displayAutoTrapMadeInput(int number) { + + AutoTrapMadeInput.setText("" + number); + } + private void displayAutoTrapAttemptInput(int number) { + + AutoTrapAttemptInput.setText("" + number); + } +} + diff --git a/app/src/main/java/com/example/ncgears/scouting/MainActivity.java b/app/src/main/java/com/example/ncgears/scouting/MainActivity.java new file mode 100644 index 0000000..036be07 --- /dev/null +++ b/app/src/main/java/com/example/ncgears/scouting/MainActivity.java @@ -0,0 +1,154 @@ +/* + + *************** Code Designed by Team 107 Team Robotics ********************* + *************** Edited for Team 1918 By Nate and Ken ********************* + + + */ + +package com.example.ncgears.scouting; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.database.sqlite.SQLiteDatabase; +import android.inputmethodservice.Keyboard; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.os.Bundle; +import android.support.design.widget.TextInputEditText; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.ncgears.scouting.customToast.CustomToast; +import com.example.ncgears.scouting.data.GetJasonData; +import com.example.ncgears.scouting.data.TeamsContract.TeamEntry; +import com.example.ncgears.scouting.data.TeamsDbHelper; + +import org.json.JSONArray; + +import java.lang.reflect.Array; +import java.util.ArrayList; + +import butterknife.ButterKnife; + +public class MainActivity extends AppCompatActivity implements View.OnKeyListener { + + + public static TextView data; + public static String TeamsList = "No teams loaded"; + public static String postData; + + SQLiteDatabase db; + + public ArrayList teams = new ArrayList<>(); + + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.activity_main); + ButterKnife.bind(this); + + // set up Database object + TeamsDbHelper mDbHelper = new TeamsDbHelper(this); + db = mDbHelper.getWritableDatabase(); + + teams = TeamsDbHelper.getTeams(db); + + if (!teams.isEmpty()){ + TeamsList = ""; + for(int i =0; i < teams.size(); i++){ + + TeamsList = TeamsList + teams.get(i) + "\n"; + } + } + + data = findViewById(R.id.TeamsList); + data.setText(TeamsList); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main_menu, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.main_activity: + startActivity(new Intent(this, MainActivity.class)); + return true; + case R.id.send_data: + startActivity(new Intent(this, SendDataActivity.class)); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { + if (keyCode != KeyEvent.KEYCODE_SPACE && keyCode != KeyEvent.KEYCODE_TAB) { + TextInputEditText inputEditText = (TextInputEditText) v; + + if (inputEditText != null) { + + switch (inputEditText.getId()) { + + } + } + } + return false; + } + + private boolean isNetworkAvailable(){ + ConnectivityManager connectivityManager + = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); + return activeNetworkInfo !=null && activeNetworkInfo.isConnected(); + } + + public void showMatch(View view) { + startActivity(new Intent(this, ScouterInitialsActivity.class)); + } + + public void showPit(View view) { + startActivity(new Intent(this, PitActivity.class)); + } + + public void sendData(View view) { + startActivity(new Intent(this, SendDataActivity.class)); + } + + public void getTeams(View view){ + + if(isNetworkAvailable()){ + + TeamsDbHelper.dropTable(db); + TeamsDbHelper.createTable(db); + GetJasonData process = new GetJasonData(this); + process.execute(); + + Toast.makeText(this, "Import Complete", Toast.LENGTH_LONG).show(); + } + else{ + + CustomToast.showLong(this, "Sorry! But your WiFi doesn't seem to be on at this time"); + + + } + + + + } +} diff --git a/app/src/main/java/com/example/ncgears/scouting/PitActivity.java b/app/src/main/java/com/example/ncgears/scouting/PitActivity.java new file mode 100644 index 0000000..ecfc50b --- /dev/null +++ b/app/src/main/java/com/example/ncgears/scouting/PitActivity.java @@ -0,0 +1,980 @@ +/* + + *************** Code Designed by Team 107 Team Robotics ********************* + *************** Edited for Team 1918 By Nate and Ken ********************* + + + */ + +package com.example.ncgears.scouting; + +import android.Manifest; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.database.sqlite.SQLiteDatabase; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Color; +import android.net.Uri; +import android.os.Bundle; +import android.os.Environment; +import android.provider.MediaStore; +import android.provider.Settings; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; +import android.support.v4.content.FileProvider; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.Spinner; +import android.widget.ArrayAdapter; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.ncgears.scouting.data.TeamsDbHelper; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; + +import butterknife.BindView; +import butterknife.ButterKnife; +import utils.FormatStringUtils; +import utils.PermissionUtils; +import utils.StringUtils; +import utils.ViewUtils; + +/** + * Created by Matt from Team 107 on 9/30/2017. + * Borrowed by Ken from Team 1918 on 1/7/2019. + */ + +public class PitActivity extends AppCompatActivity implements View.OnKeyListener { + + @BindView(R.id.pit_team_number_spinner) + public Spinner pitTeamNumberSpinner; + + @BindView(R.id.pit_power_cell_pickup_radio_group) + public RadioGroup pitPowerCellPickupRadioGroup; + + @BindView(R.id.pit_robot_weight) + public EditText pitRobotWeight; + + @BindView(R.id.pit_drive_train_spinner) + public Spinner pitDriveTrainSpinner; + + @BindView(R.id.drive_train_other) + public EditText driveTrainOther; + + @BindView(R.id.pit_programming_language_spinner) + public Spinner pitProgrammingLanguages; + + @BindView(R.id.programming_language_other) + public EditText programmingLanguageOther; + + @BindView(R.id.pit_basic_plan) + public EditText pitBasicPlan; + + @BindView(R.id.pit_auto_programs) + public EditText pitAutoPrograms; + + @BindView(R.id.pit_shoot_target_zone) + public CheckBox pitShootTargetZone; + + @BindView(R.id.pit_shoot_field_front) + public CheckBox pitShootFieldFront; + + @BindView(R.id.pit_shoot_field_diagonal) + public CheckBox pitShootFieldDiagonal; + + @BindView(R.id.pit_shoot_trench_near) + public CheckBox pitShootTrenchNear; + + @BindView(R.id.pit_shoot_trench_far) + public CheckBox pitShootTrenchFar; + + @BindView(R.id.pit_shoot_other) + public CheckBox pitShootOther; + + public String shotString = ""; + + @BindView(R.id.pit_fav_target_zone) + public CheckBox pitFavTargetZone; + + @BindView(R.id.pit_fav_field_front) + public CheckBox pitFavFieldFront; + + @BindView(R.id.pit_fav_field_diagonal) + public CheckBox pitFavFieldDiagonal; + + @BindView(R.id.pit_fav_trench_near) + public CheckBox pitFavTrenchNear; + + @BindView(R.id.pit_fav_trench_far) + public CheckBox pitFavTrenchFar; + + @BindView(R.id.pit_fav_other) + public CheckBox pitFavOther; + + public String favShotString = ""; + +// @BindView(R.id.pit_end_game_location_spinner) +// public Spinner pitEndGameLocationSpinner; + + @BindView(R.id.pit_shot_location_inner) + public CheckBox pitShotLocationInner; + + @BindView(R.id.pit_shot_location_outer) + public CheckBox pitShotLocationOuter; + + @BindView(R.id.pit_shot_location_bottom) + public CheckBox pitShotLocationBottom; + + @BindView(R.id.pit_shot_location_na) + public CheckBox pitShotLocationNa; + + public String pitShotLocationString = ""; + +// @BindView(R.id.pit_control_panel_rotate_3to5) + public CheckBox pitControlPanelRotate3to5; + +// @BindView(R.id.pit_control_panel_position) + public CheckBox pitControlPanelPosition; + +// @BindView(R.id.pit_control_panel_nothing) + public CheckBox pitControlPanelNothing; + + public String ControlPanelString = ""; + + @BindView(R.id.pit_endgame_location) + public RadioGroup pitEndgameLocation; + + @BindView(R.id.pit_drive_thru_trench) + public RadioGroup pitDriveThruTrench; + +// @BindView(R.id.pit_endgame_hang) +// public CheckBox pitEndgameHang; + + @BindView(R.id.scouterInitials_input) + public EditText scouterInitialsInput; + + + @BindView(R.id.take_photo_btn) + public Button takePhotoBtn; + + @BindView(R.id.save_pit_btn) + public Button savePitBtn; + + @BindView(R.id.pit_robot_name) + public EditText RobotNameInput; + + public ArrayList team_numbers = new ArrayList<>(); + private ArrayList pitDataStringList; + + + + + + + + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + TeamsDbHelper mDbHelper = new TeamsDbHelper(this); + SQLiteDatabase db = mDbHelper.getReadableDatabase(); + + setContentView(R.layout.activity_pit); + pitDataStringList = new ArrayList<>(); + + team_numbers = TeamsDbHelper.getTeamNumbers(db); + + ButterKnife.bind(this); + + checkForPermissions(); + + pitDriveTrainSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + if(pitDriveTrainSpinner.getSelectedItem().toString().equals("Other")){ + driveTrainOther.setVisibility(view.VISIBLE); + } + else{ + driveTrainOther.setVisibility(view.INVISIBLE); + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + + pitProgrammingLanguages.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + if(pitProgrammingLanguages.getSelectedItem().toString().equals("Other")){ + programmingLanguageOther.setVisibility(view.VISIBLE); + } + else{ + programmingLanguageOther.setVisibility(view.INVISIBLE); + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + + + // --- Drive Train spinner --- + + // Spinner drivetrainspinner = (Spinner) findViewById(R.id.pit_drive_train_spinner); +// Create an ArrayAdapter using the string array and a default spinner layout + ArrayAdapter drivetrainadapter = ArrayAdapter.createFromResource(this, + R.array.driveTrain, android.R.layout.simple_spinner_item); +// Specify the layout to use when the list of choices appears + drivetrainadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); +// Apply the adapter to the spinner + pitDriveTrainSpinner.setAdapter(drivetrainadapter); + + // --- Team Numbers spinner --- + + // Spinner teamnumberspinner = (Spinner) findViewById(R.id.pit_team_number_spinner); +// Create an ArrayAdapter using the string array and a default spinner layout + ArrayAdapter teamnumberadapter = new ArrayAdapter<>(PitActivity.this, + android.R.layout.simple_spinner_dropdown_item, team_numbers); +// Specify the layout to use when the list of choices appears + teamnumberadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); +// Apply the adapter to the spinner + pitTeamNumberSpinner.setAdapter(teamnumberadapter); + + + // --- Programming languages spinner --- + + // Spinner languagespinner = (Spinner) findViewById(R.id.pit_programming_language_spinner); +// Create an ArrayAdapter using the string array and a default spinner layout + ArrayAdapter languageadapter = ArrayAdapter.createFromResource(this, + R.array.programmingLanguages, android.R.layout.simple_spinner_item); +// Specify the layout to use when the list of choices appears + languageadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); +// Apply the adapter to the spinner + pitProgrammingLanguages.setAdapter(languageadapter); + + // --- End Game Location spinner --- + +// Spinner pitendgamelocationspinner = (Spinner) findViewById(R.id.pit_end_game_location_spinner); +// Create an ArrayAdapter using the string array and a default spinner layout + ArrayAdapter pitendgamelocationadapter = ArrayAdapter.createFromResource(this, + R.array.endgame_location, android.R.layout.simple_spinner_item); +// Specify the layout to use when the list of choices appears + pitendgamelocationadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); +// Apply the adapter to the spinner +// pitendgamelocationspinner.setAdapter(pitendgamelocationadapter); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main_menu, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.main_activity: + startActivity(new Intent(this, MainActivity.class)); + return true; + case R.id.send_data: + startActivity(new Intent(this, SendDataActivity.class)); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + public void setStringShot(View view) { + boolean checked = ((CheckBox) view).isChecked(); + String s1; + + switch (view.getId()) { + + case R.id.pit_shoot_trench_near: + s1 = pitShootTrenchNear.getText().toString() + " ,"; + if (checked) { + if (shotString.isEmpty()) { + shotString = s1; + } else { + shotString = shotString + s1; + } + } else { + if (shotString.contains(s1)) { + int start = shotString.indexOf(s1); + shotString = shotString.substring(0, start) + shotString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_shoot_trench_far: + s1 = pitShootTrenchFar.getText().toString() + " ,"; + if (checked) { + if (shotString.isEmpty()) { + shotString = s1; + } else { + shotString = shotString + s1; + } + } else { + if (shotString.contains(s1)) { + int start = shotString.indexOf(s1); + shotString = shotString.substring(0, start) + shotString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_shoot_other: + s1 = pitShootOther.getText().toString() + " ,"; + if (checked) { + if (shotString.isEmpty()) { + shotString = s1; + } else { + shotString = shotString + s1; + } + } else { + if (shotString.contains(s1)) { + int start = shotString.indexOf(s1); + shotString = shotString.substring(0, start) + shotString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_shoot_target_zone: + s1 = pitShootTargetZone.getText().toString() + " ,"; + if (checked) { + if (shotString.isEmpty()) { + shotString = s1; + } else { + shotString = shotString + s1; + } + } else { + if (shotString.contains(s1)) { + int start = shotString.indexOf(s1); + shotString = shotString.substring(0, start) + shotString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_shoot_field_diagonal: + s1 = pitShootFieldDiagonal.getText().toString() + " ,"; + if (checked) { + if (shotString.isEmpty()) { + shotString = s1; + } else { + shotString = shotString + s1; + } + } else { + if (shotString.contains(s1)) { + int start = shotString.indexOf(s1); + shotString = shotString.substring(0, start) + shotString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_shoot_field_front: + s1 = pitShootFieldFront.getText().toString() + " ,"; + if (checked) { + if (shotString.isEmpty()) { + shotString = s1; + } else { + shotString = shotString + s1; + } + } else { + if (shotString.contains(s1)) { + int start = shotString.indexOf(s1); + shotString = shotString.substring(0, start) + shotString.substring(start + s1.length()); + } + } + break; + } + } + + public void setStringFavShot(View view) { + boolean checked = ((CheckBox) view).isChecked(); + String s1; + + switch (view.getId()) { + + case R.id.pit_fav_trench_near: + s1 = pitFavTrenchNear.getText().toString() + " ,"; + if (checked) { + if (favShotString.isEmpty()) { + favShotString = s1; + } else { + favShotString = favShotString + s1; + } + } else { + if (favShotString.contains(s1)) { + int start = favShotString.indexOf(s1); + favShotString = favShotString.substring(0, start) + favShotString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_fav_trench_far: + s1 = pitFavTrenchFar.getText().toString() + " ,"; + if (checked) { + if (favShotString.isEmpty()) { + favShotString = s1; + } else { + favShotString = favShotString + s1; + } + } else { + if (favShotString.contains(s1)) { + int start = favShotString.indexOf(s1); + favShotString = favShotString.substring(0, start) + favShotString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_fav_other: + s1 = pitFavOther.getText().toString() + " ,"; + if (checked) { + if (favShotString.isEmpty()) { + favShotString = s1; + } else { + favShotString = favShotString + s1; + } + } else { + if (favShotString.contains(s1)) { + int start = favShotString.indexOf(s1); + favShotString = favShotString.substring(0, start) + favShotString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_fav_target_zone: + s1 = pitFavTargetZone.getText().toString() + " ,"; + if (checked) { + if (favShotString.isEmpty()) { + favShotString = s1; + } else { + favShotString = favShotString + s1; + } + } else { + if (favShotString.contains(s1)) { + int start = favShotString.indexOf(s1); + favShotString = favShotString.substring(0, start) + favShotString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_fav_field_diagonal: + s1 = pitFavFieldDiagonal.getText().toString() + " ,"; + if (checked) { + if (favShotString.isEmpty()) { + favShotString = s1; + } else { + favShotString = favShotString + s1; + } + } else { + if (favShotString.contains(s1)) { + int start = favShotString.indexOf(s1); + favShotString = favShotString.substring(0, start) + favShotString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_fav_field_front: + s1 = pitFavFieldFront.getText().toString() + " ,"; + if (checked) { + if (favShotString.isEmpty()) { + favShotString = s1; + } else { + favShotString = favShotString + s1; + } + } else { + if (favShotString.contains(s1)) { + int start = favShotString.indexOf(s1); + favShotString = favShotString.substring(0, start) + favShotString.substring(start + s1.length()); + } + } + break; + } + } + + public void setPowerPortShotString(View view) { + boolean checked = ((CheckBox) view).isChecked(); + String s1; + + switch (view.getId()) { + + case R.id.pit_shoot_trench_near: + s1 = pitShootTrenchNear.getText().toString() + " ,"; + if (checked) { + if (shotString.isEmpty()) { + shotString = s1; + } else { + shotString = shotString + s1; + } + } else { + if (shotString.contains(s1)) { + int start = shotString.indexOf(s1); + shotString = shotString.substring(0, start) + shotString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_shoot_trench_far: + s1 = pitShootTrenchFar.getText().toString() + " ,"; + if (checked) { + if (shotString.isEmpty()) { + shotString = s1; + } else { + shotString = shotString + s1; + } + } else { + if (shotString.contains(s1)) { + int start = shotString.indexOf(s1); + shotString = shotString.substring(0, start) + shotString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_shoot_other: + s1 = pitShootOther.getText().toString() + " ,"; + if (checked) { + if (shotString.isEmpty()) { + shotString = s1; + } else { + shotString = shotString + s1; + } + } else { + if (shotString.contains(s1)) { + int start = shotString.indexOf(s1); + shotString = shotString.substring(0, start) + shotString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_shoot_target_zone: + s1 = pitShootTargetZone.getText().toString() + " ,"; + if (checked) { + if (shotString.isEmpty()) { + shotString = s1; + } else { + shotString = shotString + s1; + } + } else { + if (shotString.contains(s1)) { + int start = shotString.indexOf(s1); + shotString = shotString.substring(0, start) + shotString.substring(start + s1.length()); + } + } + break; + } + } + + public void setControlPanelString(View view) { + boolean checked = ((CheckBox) view).isChecked(); + String s1; + +// switch (view.getId()) { +// +// case R.id.pit_control_panel_rotate_3to5: +// s1 = pitControlPanelRotate3to5.getText().toString() + " ,"; +// if (checked) { +// if (ControlPanelString.isEmpty()) { +// ControlPanelString = s1; +// } else { +// ControlPanelString = ControlPanelString + s1; +// } +// } else { +// if (ControlPanelString.contains(s1)) { +// int start = ControlPanelString.indexOf(s1); +// ControlPanelString = ControlPanelString.substring(0, start) + ControlPanelString.substring(start + s1.length()); +// } +// } +// break; +// +// case R.id.pit_control_panel_position: +// s1 = pitControlPanelPosition.getText().toString() + " ,"; +// if (checked) { +// if (ControlPanelString.isEmpty()) { +// ControlPanelString = s1; +// } else { +// ControlPanelString = ControlPanelString + s1; +// } +// } else { +// if (ControlPanelString.contains(s1)) { +// int start = ControlPanelString.indexOf(s1); +// ControlPanelString = ControlPanelString.substring(0, start) + ControlPanelString.substring(start + s1.length()); +// } +// } +// break; + +// case R.id.pit_control_panel_nothing: +// s1 = pitControlPanelNothing.getText().toString() + " ,"; +// if (checked) { +// if (ControlPanelString.isEmpty()) { +// ControlPanelString = s1; +// } else { +// ControlPanelString = ControlPanelString + s1; +// } +// } else { +// if (ControlPanelString.contains(s1)) { +// int start = ControlPanelString.indexOf(s1); +// ControlPanelString = ControlPanelString.substring(0, start) + ControlPanelString.substring(start + s1.length()); +// } +// } +// break; +// } + } + + public void setPitShotLocationString(View view) { + boolean checked = ((CheckBox) view).isChecked(); + String s1; + + switch (view.getId()) { + + case R.id.pit_shot_location_bottom: + s1 = pitShotLocationBottom.getText().toString() + " ,"; + if (checked) { + if (pitShotLocationString.isEmpty()) { + pitShotLocationString = s1; + } else { + pitShotLocationString = pitShotLocationString + s1; + } + } else { + if (pitShotLocationString.contains(s1)) { + int start = pitShotLocationString.indexOf(s1); + pitShotLocationString = pitShotLocationString.substring(0, start) + pitShotLocationString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_shot_location_inner: + s1 = pitShotLocationInner.getText().toString() + " ,"; + if (checked) { + if (pitShotLocationString.isEmpty()) { + pitShotLocationString = s1; + } else { + pitShotLocationString = pitShotLocationString + s1; + } + } else { + if (pitShotLocationString.contains(s1)) { + int start = pitShotLocationString.indexOf(s1); + pitShotLocationString = pitShotLocationString.substring(0, start) + pitShotLocationString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_shot_location_outer: + s1 = pitShotLocationOuter.getText().toString() + " ,"; + if (checked) { + if (pitShotLocationString.isEmpty()) { + pitShotLocationString = s1; + } else { + pitShotLocationString = pitShotLocationString + s1; + } + } else { + if (pitShotLocationString.contains(s1)) { + int start = pitShotLocationString.indexOf(s1); + pitShotLocationString = pitShotLocationString.substring(0, start) + pitShotLocationString.substring(start + s1.length()); + } + } + break; + + case R.id.pit_shot_location_na: + s1 = pitShotLocationNa.getText().toString() + " ,"; + if (checked) { + if (pitShotLocationString.isEmpty()) { + pitShotLocationString = s1; + } else { + pitShotLocationString = pitShotLocationString + s1; + } + } else { + if (pitShotLocationString.contains(s1)) { + int start = pitShotLocationString.indexOf(s1); + pitShotLocationString = pitShotLocationString.substring(0, start) + pitShotLocationString.substring(start + s1.length()); + } + } + break; + } + } + + @Override + protected void onResume() { + super.onResume(); + + pitTeamNumberSpinner.setOnKeyListener(this); + pitDriveTrainSpinner.setOnKeyListener(this); +// pitEndGameLocationSpinner.setOnKeyListener(this); + driveTrainOther.setOnKeyListener(this); + pitRobotWeight.setOnKeyListener(this); + pitProgrammingLanguages.setOnKeyListener(this); + programmingLanguageOther.setOnKeyListener(this); + pitAutoPrograms.setOnKeyListener(this); + pitDriveThruTrench.setOnKeyListener(this); + pitBasicPlan.setOnKeyListener(this); + pitPowerCellPickupRadioGroup.setOnKeyListener(this); + pitEndgameLocation.setOnKeyListener(this); + } + + + @Override + protected void onPause() { + super.onPause(); + + pitTeamNumberSpinner.setOnKeyListener(null); + pitDriveTrainSpinner.setOnKeyListener(null); + driveTrainOther.setOnKeyListener(null); + pitRobotWeight.setOnKeyListener(null); + pitProgrammingLanguages.setOnKeyListener(null); + programmingLanguageOther.setOnKeyListener(null); + pitAutoPrograms.setOnKeyListener(null); + pitDriveThruTrench.setOnKeyListener(null); +// pitEndgameHang.setOnKeyListener(null); + pitBasicPlan.setOnKeyListener(null); +// pitEndGameLocationSpinner.setOnKeyListener(null); + pitPowerCellPickupRadioGroup.setOnKeyListener(null); + pitEndgameLocation.setOnKeyListener(null); + + } + + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { + + + return false; + } + + public void savePitData(View view) throws IOException { + String state = Environment.getExternalStorageState(); + boolean allInputsPassed = false; + + // ****** Check Required fields set focus to field if it hasn't been filled out ****** + + + if (pitTeamNumberSpinner.getSelectedItem().toString().equals("Select Team Number") ) { + setSpinnerError(pitTeamNumberSpinner, "Select a Team Number."); + ViewUtils.requestFocus(pitTeamNumberSpinner, this); + }else if (pitProgrammingLanguages.getSelectedItem().toString().equals("") ) { + setSpinnerError(pitProgrammingLanguages, "Select a Programming Language."); + ViewUtils.requestFocus(pitProgrammingLanguages, this); + }else if(pitDriveTrainSpinner.getSelectedItem().toString().equals("")){ + setSpinnerError(pitDriveTrainSpinner, "Select a drive train."); + ViewUtils.requestFocus(pitDriveTrainSpinner, this); + } else if (StringUtils.isEmptyOrNull(pitRobotWeight.getText().toString())) { + pitRobotWeight.setError(getText(R.string.pitRobotWeightError)); + ViewUtils.requestFocus(pitRobotWeight, this); + } else if (StringUtils.isEmptyOrNull(scouterInitialsInput.getText().toString())) { + scouterInitialsInput.setError(getText(R.string.scouterInitialsError)); + ViewUtils.requestFocus(scouterInitialsInput, this); + } else { + allInputsPassed = true; + } + if (!allInputsPassed) { + return; + } + + + final RadioButton pitDriveThruTrenchbtn = findViewById(pitDriveThruTrench.getCheckedRadioButtonId()); +// final RadioButton pitEndgameHangbtn = findViewById(pitEndgameHang.getCheckedRadioButtonId()); + final RadioButton pitPowerCellPickUpRadioBtn = findViewById(pitPowerCellPickupRadioGroup.getCheckedRadioButtonId()); + final RadioButton pitEndgameLocationBtn = findViewById(pitEndgameLocation.getCheckedRadioButtonId()); + + if(PermissionUtils.getPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + if (Environment.MEDIA_MOUNTED.equals(state)) { + File dir = new File(Environment.getExternalStorageDirectory() + "/Scouting"); + //create csv file + File file = new File(dir, "Pit" + Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID) + ".csv"); + + pitDataStringList.add(pitTeamNumberSpinner.getSelectedItem().toString()); + pitDataStringList.add(RobotNameInput.getText().toString()); + pitDataStringList.add(pitRobotWeight.getText().toString()); + pitDataStringList.add(pitDriveTrainSpinner.getSelectedItem().toString()); + pitDataStringList.add(driveTrainOther.getText().toString()); + pitDataStringList.add(pitProgrammingLanguages.getSelectedItem().toString()); + pitDataStringList.add(programmingLanguageOther.getText().toString()); + pitDataStringList.add(pitAutoPrograms.getText().toString()); + pitDataStringList.add(pitPowerCellPickUpRadioBtn.getText().toString()); + pitDataStringList.add(shotString); + pitDataStringList.add(favShotString); +// pitDataStringList.add(pitDriveThruTrenchbtn.getText().toString()); + pitDataStringList.add(pitShotLocationString); + pitDataStringList.add(ControlPanelString); +// pitDataStringList.add(pitEndGameLocationSpinner.getSelectedItem().toString()); + pitDataStringList.add(pitEndgameLocationBtn.getText().toString()); + pitDataStringList.add(pitBasicPlan.getText().toString()); + pitDataStringList.add(scouterInitialsInput.getText().toString()); + + + + + + String message = FormatStringUtils.addDelimiter(pitDataStringList, "|") + "\n"; + + + //Output data to file + try { + FileOutputStream fileOutputStream = new FileOutputStream(file, true); + fileOutputStream.write(message.getBytes()); + fileOutputStream.close(); + + Toast.makeText(getApplicationContext(), "Saved!", Toast.LENGTH_LONG).show(); + } catch (IOException e) { + Toast.makeText(getApplicationContext(), "IOException! Go talk to the programmers!", Toast.LENGTH_LONG).show(); + Log.d("Scouting", e.getMessage()); + } + } else { + Toast.makeText(getApplicationContext(), "SD card not found", Toast.LENGTH_LONG).show(); + } + + clearData(); + pitTeamNumberSpinner.requestFocus(); + } + + + + + } + + public void takePhoto(View view) { + String name = pitTeamNumberSpinner.getSelectedItem().toString(); + + if(PermissionUtils.getPermissions(this, Manifest.permission.CAMERA) && + PermissionUtils.getPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) && + PermissionUtils.getPermissions(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { + if (!StringUtils.isEmptyOrNull(name)) { + File dir = new File(Environment.getExternalStorageDirectory() + "/Scouting/Photos"); + dir.mkdirs(); + + File file = new File(dir, name + ".jpg"); + + try { + file.createNewFile(); + } catch (IOException e) { + Log.d("Scouting", e.getMessage()); + } + + Uri outputUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", file); + + Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + if (takePictureIntent.resolveActivity(getPackageManager()) != null) { + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri); + startActivityForResult(takePictureIntent, 0); + } + } else { + //setSpinnerError(pitTeamNumberInputLayout, "Select a Team Number."); + ViewUtils.requestFocus(pitTeamNumberSpinner, this); + } + } else { + checkForPermissions(); + } + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == 0) { + if(resultCode == RESULT_OK) { + compressPhoto(); + } + } + } + + private void compressPhoto() { + try { + String name = pitTeamNumberSpinner.getSelectedItem().toString(); + + File dir = new File(Environment.getExternalStorageDirectory() + "/Scouting/Photos"); + File file = new File(dir, name + ".jpg"); + + FileInputStream inputStream = new FileInputStream(file); + Bitmap bitmap = BitmapFactory.decodeStream(inputStream); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + bitmap.compress(Bitmap.CompressFormat.JPEG, 25, out); + + FileOutputStream outputStream = new FileOutputStream(file); + outputStream.write(out.toByteArray()); + inputStream.close(); + out.close(); + outputStream.close(); + + Toast.makeText(this, "Photo taken!", Toast.LENGTH_SHORT).show(); + } catch (IOException e) { + Log.d("Scouting", e.getMessage()); + Toast.makeText(this, "Failed to save photo. Try again!", Toast.LENGTH_LONG).show(); + } + } + + private void setSpinnerError(Spinner spinner, String error){ + View selectedView = spinner.getSelectedView(); + if (selectedView instanceof TextView){ + spinner.requestFocus(); + TextView selectedTextView = (TextView) selectedView; + selectedTextView.setError("error"); + selectedTextView.setTextColor(Color.RED); + selectedTextView.setText(error); + + } + } + + public void clearData() { + pitTeamNumberSpinner.setSelection(0); + pitRobotWeight.setText(null); + pitDriveTrainSpinner.setSelection(0); + driveTrainOther.setText(null); + pitProgrammingLanguages.setSelection(0); + programmingLanguageOther.setText(null); + pitAutoPrograms.setText(null); + scouterInitialsInput.setText(null); + pitControlPanelNothing.setChecked(false); + pitControlPanelPosition.setChecked(false); + pitControlPanelRotate3to5.setChecked(false); + pitShootTrenchNear.setChecked(false); + pitShootTrenchFar.setChecked(false); + pitShootOther.setChecked(false); + pitShootFieldFront.setChecked(false); + pitShootFieldDiagonal.setChecked(false); + pitShootTargetZone.setChecked(false); +// pitEndgameHang.setChecked(false); + pitDriveThruTrench.clearCheck(); + pitShotLocationOuter.setChecked(false); + pitShotLocationInner.setChecked(false); + pitShotLocationBottom.setChecked(false); + pitShotLocationNa.setChecked(false); + pitBasicPlan.setText(null); +// pitEndGameLocationSpinner.setSelection(0); + ControlPanelString = ""; + shotString = ""; + pitShotLocationString = ""; + RobotNameInput.setText(null); + + pitDataStringList.clear(); + } + + private void checkForPermissions() { + int cameraPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA); + if (cameraPermission != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 1); + } + } + + + +} diff --git a/app/src/main/java/com/example/ncgears/scouting/ScouterInitialsActivity.java b/app/src/main/java/com/example/ncgears/scouting/ScouterInitialsActivity.java new file mode 100644 index 0000000..664ce93 --- /dev/null +++ b/app/src/main/java/com/example/ncgears/scouting/ScouterInitialsActivity.java @@ -0,0 +1,105 @@ +/* + + *************** Code Designed by Team 107 Team Robotics ********************* + *************** Edited for Team 1918 By Nate and Ken ********************* + + + */ + +package com.example.ncgears.scouting; + +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.design.widget.TextInputEditText; +import android.support.design.widget.TextInputLayout; +import android.support.v7.app.AppCompatActivity; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; + +import butterknife.BindView; +import butterknife.ButterKnife; +import utils.StringUtils; +import utils.ViewUtils; + +public class ScouterInitialsActivity extends AppCompatActivity implements View.OnKeyListener { + + @BindView(R.id.scouterInitials_input_layout) + public TextInputLayout scouterInitialsInputLayout; + + @BindView(R.id.scouterInitials_input) + public TextInputEditText scouterInitialsInput; + + private static String initials; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.activity_scouter_initials); + ButterKnife.bind(this); + + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main_menu, menu); + return true; + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.main_activity: + startActivity(new Intent(this, MainActivity.class)); + return true; + case R.id.send_data: + startActivity(new Intent(this, SendDataActivity.class)); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { + if (keyCode != KeyEvent.KEYCODE_SPACE && keyCode != KeyEvent.KEYCODE_TAB) { + TextInputEditText inputEditText = (TextInputEditText) v; + + if (inputEditText != null) { + + switch (inputEditText.getId()) { + case R.id.scouterInitials_input_layout: + scouterInitialsInputLayout.setError(null); + break; + } + } + } + return false; + } + + public static String getInitials() { + return initials; + } + + public void submitInitials(View view) { + initials = getTextInputLayoutString(scouterInitialsInputLayout); + scouterInitialsInput.setText(null); + + if(!StringUtils.isEmptyOrNull(initials)) + startActivity(new Intent(this, AutonActivity.class)); + else + scouterInitialsInputLayout.setError(getText(R.string.scouterInitialsError)); + } + + private String getTextInputLayoutString(@NonNull TextInputLayout textInputLayout) { + final EditText editText = textInputLayout.getEditText(); + return editText != null && editText.getText() != null ? editText.getText().toString() : ""; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ncgears/scouting/SendDataActivity.java b/app/src/main/java/com/example/ncgears/scouting/SendDataActivity.java new file mode 100644 index 0000000..100b0d5 --- /dev/null +++ b/app/src/main/java/com/example/ncgears/scouting/SendDataActivity.java @@ -0,0 +1,211 @@ +/* + + *************** Code Designed by Team 107 Team Robotics ********************* + *************** Edited for Team 1918 By Nate and Ken ********************* + + + */ + +package com.example.ncgears.scouting; + +import android.Manifest; +import android.app.ActionBar; +import android.bluetooth.BluetoothAdapter; +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.net.Uri; +import android.os.Bundle; +import android.os.Environment; +import android.os.Message; +import android.os.Parcelable; +import android.provider.Settings; +import android.support.annotation.NonNull; +import android.support.design.widget.TextInputEditText; +import android.support.design.widget.TextInputLayout; +import android.support.v4.content.FileProvider; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.EditText; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.TextView; +import android.widget.Toast; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import utils.FormatStringUtils; +import utils.PermissionUtils; + +import static android.os.Environment.getExternalStorageDirectory; + +/** + * Created by Matt on 10/9/2017. + */ + +public class SendDataActivity extends AppCompatActivity { + + // @BindView(R.id.matchOrPit_RadiobtnGrp) + public RadioGroup matchOrPitRadiobtnGrp; + + // @BindView(R.id.concatFolder_editText) + public EditText concatFolderEditText; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_send_data); + + ButterKnife.bind(this); + } + + /* This method will display the options menu when the icon is pressed + * and this will inflate the menu options for the user to choose + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main_menu, menu); + return true; + } + + /*This method will launch the correct activity + *based on the menu option user presses + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.main_activity: + startActivity(new Intent(this, MainActivity.class)); + return true; + case R.id.send_data: + startActivity(new Intent(this, SendDataActivity.class)); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + public void concatenateData(View view) { + if(PermissionUtils.getPermissions(this, Manifest.permission.READ_EXTERNAL_STORAGE) && + PermissionUtils.getPermissions(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { + RadioButton radioButton = findViewById(matchOrPitRadiobtnGrp.getCheckedRadioButtonId()); + + if(radioButton != null) { + String dir = Environment.getExternalStorageDirectory() + "/" + concatFolderEditText.getText().toString(); + + File folder = new File(dir); + + if(folder.exists() && concatFolderEditText.getText().toString().length() > 0) { + File[] files = folder.listFiles(); + + StringBuilder builder = new StringBuilder(); + FileReader fileReader; + BufferedReader bufferedReader; + FileOutputStream fileOutputStream; + + String type = radioButton.getText().toString().contains("Match") ? "Match" : "Pit"; + + if (files != null) { + try { + int fileCount = 0; + for (File file : files) { + if (file.getName().contains(type)) { + fileCount++; + fileReader = new FileReader(file); + bufferedReader = new BufferedReader(fileReader); + + String line; + while ((line = bufferedReader.readLine()) != null) { + builder.append(line + '\n'); + } + } + } + fileOutputStream = new FileOutputStream(new File(dir, "new.csv"), false); + fileOutputStream.write("teamNumber,matchNumber,startingLocation,baseline,autoCubesInSwitch,autoCubesInScale,numberOfCubesInExchange,numberOfCubesInTheirSwitch,numberOfCubesInOpSwitch,NumberOfCubesInScale,cubePickup,climb,canHelpOthersClimb,onPlatform,defense,fouls,scouterInitials".getBytes()); + fileOutputStream.write(builder.toString().getBytes()); + fileOutputStream.close(); + + Toast.makeText(this, "Successfully concatenated " + fileCount + " " + type + " files to new.csv!", Toast.LENGTH_LONG).show(); + + } catch (IOException e) { + Log.d("Scouting", e.getMessage()); + Toast.makeText(this, "Failed to concatenate data.", Toast.LENGTH_LONG).show(); + } + } + + } else { + Toast.makeText(this, "Invalid folder name!", Toast.LENGTH_LONG).show(); + } + } else { + Toast.makeText(this, "Select an option!", Toast.LENGTH_SHORT).show(); + } + } + } + + public void sendMatchData(View view) { + if(PermissionUtils.getPermissions(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { + Intent intent = new Intent(Intent.ACTION_SEND); + String file = "storage/emulated/0/Scouting/Match" + Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID) + ".csv"; + intent.setType("text/plain"); + intent.setPackage("com.android.bluetooth"); + intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", new File(file))); + startActivity(Intent.createChooser(intent, "Share app")); + } + } + + public void sendPitData(View view) { + if(PermissionUtils.getPermissions(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { + Intent intent = new Intent(Intent.ACTION_SEND); + String file = "storage/emulated/0/Scouting/Pit" + Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID) + ".csv"; + intent.setType("text/plain"); + intent.setPackage("com.android.bluetooth"); + intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", new File(file))); + startActivity(Intent.createChooser(intent, "Share app")); + } + } + + public void sendRobotPhotos(View view) { + if(PermissionUtils.getPermissions(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { + Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); + intent.setType("image/jpeg"); + intent.setPackage("com.android.bluetooth"); + String dir = "storage/emulated/0/Scouting/Photos/"; + + File folder = new File(dir); + File[] photos = folder.listFiles(); + + if(photos != null) { + ArrayList toSend = new ArrayList<>(); + + for (int i = 0; i < photos.length; i++) { + toSend.add(FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", photos[i])); + } + + intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, toSend); + startActivity(Intent.createChooser(intent, "Share app")); + } else { + Toast.makeText(this, "No photos!", Toast.LENGTH_SHORT).show(); + } + } + } + + private String getTextInputLayoutString(@NonNull TextInputLayout textInputLayout) { + final EditText editText = textInputLayout.getEditText(); + return editText != null && editText.getText() != null ? editText.getText().toString() : ""; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ncgears/scouting/TeleopActivity.java b/app/src/main/java/com/example/ncgears/scouting/TeleopActivity.java new file mode 100644 index 0000000..e14b8cf --- /dev/null +++ b/app/src/main/java/com/example/ncgears/scouting/TeleopActivity.java @@ -0,0 +1,1362 @@ +/* + +*************** Code Designed by Team 107 Team Robotics ********************* +*************** Edited for Team 1918 By Nate and Ken ********************* + + + */ + +package com.example.ncgears.scouting; + +import static android.R.attr.value; +import static com.example.ncgears.scouting.AutonActivity.AUTON_STRING_EXTRA; +import static com.example.ncgears.scouting.AutonActivity.MATCH_STRING_EXTRA; +import static com.example.ncgears.scouting.AutonActivity.TEAMNUMBER_STRING_EXTRA; + +import android.Manifest; +import android.content.Intent; +import android.graphics.Color; +import android.os.Bundle; +import android.os.Environment; +import android.provider.Settings; +import android.support.annotation.NonNull; +import android.support.design.widget.TextInputEditText; +import android.support.design.widget.TextInputLayout; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.Toast; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; + +import butterknife.BindView; +import butterknife.ButterKnife; +import utils.FormatStringUtils; +import utils.PermissionUtils; +import utils.StringUtils; +import utils.ViewUtils; + + +public class TeleopActivity extends AppCompatActivity implements View.OnKeyListener { + /*This area sets and binds all of the variables that we will use in the auton activity*/ + + @BindView(R.id.teleop_high_attempt_input_layout) + public TextInputLayout teleopHighAttemptInputLayout; + + @BindView(R.id.teleop_high_made_input_layout) + public TextInputLayout teleopHighMadeInputLayout; + + @BindView(R.id.teleop_trap_made_input_layout) + public TextInputLayout teleopTrapMadeInputLayout; + + @BindView(R.id.teleop_trap_attempt_input_layout) + public TextInputLayout teleopTrapAttemptInputLayout; + + @BindView(R.id.teleop_low_attempt_input_layout) + public TextInputLayout teleopLowAttemptInputLayout; + + @BindView(R.id.teleop_low_made_input_layout) + public TextInputLayout teleopLowMadeInputLayout; + + @BindView(R.id.teleop_high_attempts_input) + public TextInputEditText teleopHighAttemptsInput; + + @BindView(R.id.teleop_high_made_input) + public TextInputEditText teleopHighMadeInput; + + @BindView(R.id.teleop_trap_attempt_input) + public TextInputEditText teleopTrapAttemptsInput; + + @BindView(R.id.teleop_trap_made_input) + public TextInputEditText teleopTrapMadeInput; + + @BindView(R.id.teleop_low_attempt_input) + public TextInputEditText teleopLowAttemptInput; + + @BindView(R.id.teleop_low_made_input) + public TextInputEditText teleopLowMadeInput; + + @BindView(R.id.defense_rating_radio_group) + public RadioGroup defenseRatingRadioGroup; + + @BindView(R.id.power_cell_pickup_radio_group) + public RadioGroup powerCellPickupRadioGroup; + + @BindView(R.id.low_port_dump_radio_group) + public RadioGroup lowPortDumpRadioGroup; + + @BindView(R.id.under_trench_radio_group) + public RadioGroup underTrenchRadioGroup; + + @BindView(R.id.power_cell_placement_rating_radio_group) + public RadioGroup powerCellPlacementRatingRadioGroup; + + @BindView(R.id.control_panel_rating_radio_group) + public RadioGroup controlPanelRadingRadioGroup; + + @BindView(R.id.counter_defense_effectiveness) + public RadioGroup counterDefenseEffectiveness; + + @BindView(R.id.end_game_location_spinner) + public Spinner endGameLocationSpinner; + + @BindView(R.id.climb_time_radio_group) + public RadioGroup climbTimeRadioGroup; + + //@BindView(R.id.cycle_time_spinner) + // public Spinner cycleTimeSpinner; + + @BindView(R.id.cycle_time_radio_group) + public RadioGroup cycleTimeRadioGroup; + + @BindView(R.id.overall_effectiveness_radio_group) + public RadioGroup overallEffectivenessRadioGoup; + + @BindView(R.id.trained_drive_team_radio_group) + public RadioGroup trainedDriveTeamRadioGoup; + + @BindView(R.id.observe_Power_Cell_Pickup) + public CheckBox observPowerCellPickup; + + @BindView(R.id.observ_died_back) + public CheckBox observDiedBack; + + @BindView(R.id.observ_died_mid) + public CheckBox observDiedMid; + + @BindView(R.id.observ_dns) + public CheckBox observDns; + + @BindView(R.id.observ_fast) + public CheckBox observFast; + + @BindView(R.id.observ_fell_apart) + public CheckBox observFellApart; + + @BindView(R.id.observ_fell_over) + public CheckBox observFellOver; + + @BindView(R.id.control_panel_issues) + public CheckBox observPanelIssues; + + @BindView(R.id.observ_jerky) + public CheckBox observJerky; + + @BindView(R.id.observ_not_much) + public CheckBox observNotMuch; + + @BindView(R.id.observ_penalties) + public CheckBox observPenalties; + + @BindView(R.id.observ_played_defense) + public CheckBox observPlayedDefense; + + @BindView(R.id.observ_slow) + public CheckBox observSlow; + + @BindView(R.id.observ_slowed_by_robot) + public CheckBox observSlowedByRobot; + + @BindView(R.id.observ_smooth) + public CheckBox observsmooth; + + @BindView(R.id.observ_average_speed) + public CheckBox observAverageSpeed; + + @BindView(R.id.observ_power_cell_stuck_intake) + public CheckBox observPowerCellStuckIntake; + +// @BindView(R.id.observ_hung_up_power_cell) +// public CheckBox observHungUpPowerCell; +// +// @BindView(R.id.observ_fell_off_switch) +// public CheckBox observFellOffSwitch; + + @BindView(R.id.observ_hung_up) + public CheckBox observHungUp; + + @BindView(R.id.type_high_shooter) + public CheckBox typeHighShooter; + + @BindView(R.id.type_low_shooter) + public CheckBox typeLowShooter; + + @BindView(R.id.type_feeder_bot) + public CheckBox typeFeederBot; + + @BindView(R.id.type_control_panel) + public CheckBox typeControlPanel; + + @BindView(R.id.type_defense_bot) + public CheckBox typeDefenseBot; + + @BindView(R.id.type_counter_defense_bot) + public CheckBox typeCounterDefenseBot; + + @BindView(R.id.tele_shoot_target_zone) + public CheckBox teleShootTargetZone; + + @BindView(R.id.tele_shoot_field_front) + public CheckBox teleShootFieldFront; + + @BindView(R.id.tele_shoot_field_diagonal) + public CheckBox teleShootFieldDiagonal; + + @BindView(R.id.tele_shoot_trench_near) + public CheckBox teleShootTrenchNear; + + @BindView(R.id.tele_shoot_trench_far) + public CheckBox teleShootTrenchFar; + + @BindView(R.id.tele_shoot_other) + public CheckBox teleShootOther; + + + // @BindView(R.id.type_of_bot_spinner) + // public Spinner typeOfBotSpinner; + + @BindView(R.id.summary_input) + public EditText summaryInput; + + @BindView(R.id.issues_input) + public EditText issuesInput; + + public String observations = ""; + public String typeOfBot = ""; + public String shotFrom = ""; + + @BindView(R.id.save_btn) + public Button saveBtn; + + int teleopHighAttempt = 0; + int teleopHighMissed = 0; + int teleopHighMade = 0; + int teleopLowAttempt = 0; + int teleopLowMissed = 0; + int teleopLowMade = 0; + int teleopTrapAttempt = 0; + int teleopTrapMissed = 0; + int teleopTrapMade = 0; + + + + + public String auton; + public String matchNumber; + public String teamNumber; + + private ArrayList teleopDataStringList; +/* + *When this activity is first called, + *we will call the activity_auton layout so we can display + *the user interface + */ + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_teleop); + + ButterKnife.bind(this); + + Bundle bundle = getIntent().getExtras(); + auton = bundle.getString(AUTON_STRING_EXTRA); + matchNumber = bundle.getString(MATCH_STRING_EXTRA); + teamNumber = bundle.getString(TEAMNUMBER_STRING_EXTRA); + + getSupportActionBar().setTitle("Match: " + matchNumber + " - Team: " + teamNumber); + + teleopDataStringList = new ArrayList<>(); + + displayHighAttemptInput(teleopHighAttempt); + displayHighMade(teleopHighMade); + displayLowAttemptInput(teleopLowAttempt); + displayLowMadeInput(teleopLowMade); + displayTrapMade(teleopTrapMade); + displayTrapAttemptInput(teleopTrapAttempt); + + + // --- End Game Location spinner --- + + Spinner endgamelocationspinner = (Spinner) findViewById(R.id.end_game_location_spinner); +// Create an ArrayAdapter using the string array and a default spinner layout + ArrayAdapter endgamelocationadapter = ArrayAdapter.createFromResource(this, + R.array.endgame_location, android.R.layout.simple_spinner_item); +// Specify the layout to use when the list of choices appears + endgamelocationadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); +// Apply the adapter to the spinner + endgamelocationspinner.setAdapter(endgamelocationadapter); + + + // --- Cycle Time spinner --- + +/* Spinner cycletimespinner = (Spinner) findViewById(R.id.cycle_time_spinner); +// Create an ArrayAdapter using the string array and a default spinner layout + ArrayAdapter cycletimeadapter = ArrayAdapter.createFromResource(this, + R.array.cycle_time_spinner, android.R.layout.simple_spinner_item); +// Specify the layout to use when the list of choices appears + cycletimeadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); +// Apply the adapter to the spinner + cycletimespinner.setAdapter(cycletimeadapter); +*/ + // --- Type of Bot Spinner --- + +/* Spinner typeofbotspinner = (Spinner) findViewById(R.id.type_of_bot_spinner); +// Create an ArrayAdapter using the string array and a default spinner layout + ArrayAdapter typeofbotadapter = ArrayAdapter.createFromResource(this, + R.array.bot_type_array, android.R.layout.simple_spinner_item); +// Specify the layout to use when the list of choices appears + typeofbotadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); +// Apply the adapter to the spinner + typeofbotspinner.setAdapter(typeofbotadapter); +*/ + } + + + /*If this activity is resumed from a paused state the data + *will be set to what they previously were set to + */ + @Override + protected void onResume() { + super.onResume(); + + teleopHighAttemptsInput.setOnKeyListener(this); + teleopHighMadeInput.setOnKeyListener(this); + teleopTrapAttemptsInput.setOnKeyListener(this); + teleopTrapMadeInput.setOnKeyListener(this); + teleopLowAttemptInput.setOnKeyListener(this); + teleopLowMadeInput.setOnKeyListener(this); + controlPanelRadingRadioGroup.setOnKeyListener(this); + counterDefenseEffectiveness.setOnKeyListener(this); + endGameLocationSpinner.setOnKeyListener(this); + climbTimeRadioGroup.setOnKeyListener(this); + cycleTimeRadioGroup.setOnKeyListener(this); + overallEffectivenessRadioGoup.setOnKeyListener(this); + defenseRatingRadioGroup.setOnKeyListener(this); + powerCellPlacementRatingRadioGroup.setOnKeyListener(this); + trainedDriveTeamRadioGoup.setOnKeyListener(this); + powerCellPickupRadioGroup.setOnKeyListener(this); + lowPortDumpRadioGroup.setOnKeyListener(this); + underTrenchRadioGroup.setOnKeyListener(this); + observsmooth.setOnKeyListener(this); + observSlowedByRobot.setOnKeyListener(this); + observSlow.setOnKeyListener(this); + observPlayedDefense.setOnKeyListener(this); + observPenalties.setOnKeyListener(this); + observNotMuch.setOnKeyListener(this); + observJerky.setOnKeyListener(this); + observPanelIssues.setOnKeyListener(this); + observFellOver.setOnKeyListener(this); + observFellApart.setOnKeyListener(this); + observFast.setOnKeyListener(this); + observDns.setOnKeyListener(this); + observDiedMid.setOnKeyListener(this); + observDiedBack.setOnKeyListener(this); + observPowerCellPickup.setOnKeyListener(this); + observAverageSpeed.setOnKeyListener(this); + observPowerCellStuckIntake.setOnKeyListener(this); +// observHungUpPowerCell.setOnKeyListener(this); +// observFellOffSwitch.setOnKeyListener(this); + observHungUp.setOnKeyListener(this); + typeHighShooter.setOnKeyListener(this); + typeLowShooter.setOnKeyListener(this); + typeFeederBot.setOnKeyListener(this); + typeControlPanel.setOnKeyListener(this); + typeCounterDefenseBot.setOnKeyListener(this); + typeDefenseBot.setOnKeyListener(this); + teleShootTargetZone.setOnKeyListener(this); + teleShootFieldFront.setOnKeyListener(this); + teleShootFieldDiagonal.setOnKeyListener(this); + teleShootTrenchNear.setOnKeyListener(this); + teleShootTrenchFar.setOnKeyListener(this); + teleShootOther.setOnKeyListener(this); + // typeOfBotSpinner.setOnKeyListener(this); + summaryInput.setOnKeyListener(this); + issuesInput.setOnKeyListener(this); + + } + + /*If this activity enters a paused state the data will be set to null*/ + @Override + protected void onPause() { + super.onPause(); + + teleopHighAttemptsInput.setOnKeyListener(null); + teleopHighMadeInput.setOnKeyListener(null); + teleopTrapAttemptsInput.setOnKeyListener(null); + teleopTrapMadeInput.setOnKeyListener(null); + teleopLowAttemptInput.setOnKeyListener(null); + teleopLowMadeInput.setOnKeyListener(null); + controlPanelRadingRadioGroup.setOnKeyListener(null); + counterDefenseEffectiveness.setOnKeyListener(null); + endGameLocationSpinner.setOnKeyListener(null); + climbTimeRadioGroup.setOnKeyListener(null); + cycleTimeRadioGroup.setOnKeyListener(null); + overallEffectivenessRadioGoup.setOnKeyListener(null); + defenseRatingRadioGroup.setOnKeyListener(null); + powerCellPlacementRatingRadioGroup.setOnKeyListener(null); + trainedDriveTeamRadioGoup.setOnKeyListener(null); + powerCellPickupRadioGroup.setOnKeyListener(null); + lowPortDumpRadioGroup.setOnKeyListener(null); + underTrenchRadioGroup.setOnKeyListener(null); + observsmooth.setOnKeyListener(null); + observSlowedByRobot.setOnKeyListener(null); + observSlow.setOnKeyListener(null); + observPlayedDefense.setOnKeyListener(null); + observPenalties.setOnKeyListener(null); + observNotMuch.setOnKeyListener(null); + observJerky.setOnKeyListener(null); + observPanelIssues.setOnKeyListener(null); + observFellOver.setOnKeyListener(null); + observFellApart.setOnKeyListener(null); + observFast.setOnKeyListener(null); + observDns.setOnKeyListener(null); + observDiedMid.setOnKeyListener(null); + observDiedBack.setOnKeyListener(null); + observPowerCellPickup.setOnKeyListener(null); + observAverageSpeed.setOnKeyListener(null); + observPowerCellStuckIntake.setOnKeyListener(null); +// observHungUpPowerCell.setOnKeyListener(null); +// observFellOffSwitch.setOnKeyListener(null); + observHungUp.setOnKeyListener(null); + typeHighShooter.setOnKeyListener(null); + typeLowShooter.setOnKeyListener(null); + typeFeederBot.setOnKeyListener(null); + typeControlPanel.setOnKeyListener(null); + typeCounterDefenseBot.setOnKeyListener(null); + typeDefenseBot.setOnKeyListener(null); + teleShootTargetZone.setOnKeyListener(null); + teleShootFieldFront.setOnKeyListener(null); + teleShootFieldDiagonal.setOnKeyListener(null); + teleShootTrenchNear.setOnKeyListener(null); + teleShootTrenchFar.setOnKeyListener(null); + teleShootOther.setOnKeyListener(null); + //typeOfBotSpinner.setOnKeyListener(null); + summaryInput.setOnKeyListener(null); + issuesInput.setOnKeyListener(null); + + } + + /* This method will display the options menu when the icon is pressed + * and this will inflate the menu options for the user to choose + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main_menu, menu); + return true; + } + + /*This method will launch the correct activity + *based on the menu option user presses + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.main_activity: + startActivity(new Intent(this, MainActivity.class)); + return true; + case R.id.send_data: + startActivity(new Intent(this, SendDataActivity.class)); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + private void setSpinnerError(Spinner spinner, String error){ + View selectedView = spinner.getSelectedView(); + if (selectedView instanceof TextView){ + spinner.requestFocus(); + TextView selectedTextView = (TextView) selectedView; + selectedTextView.setError("error"); + selectedTextView.setTextColor(Color.RED); + selectedTextView.setText(error); + + } + } + + //Teleop high shots + public void decreaseHighAttempts(View view) { + if (teleopHighMissed != 0) { + teleopHighMissed -= 1; + teleopHighAttempt -=1; + + displayHighAttemptInput(teleopHighMissed); + } + } + + public void increaseHighAttempts(View view) { + if (teleopHighMissed <= 800) { + teleopHighMissed += 1; + teleopHighAttempt += 1; + displayHighAttemptInput(teleopHighMissed); + } + } + + private void displayHighAttemptInput(int number) { + teleopHighAttemptsInput.setText("" + number); + } + + //Teleop High Made + public void decreaseHighMadeInput(View view) { + if (teleopHighMade != 0) { + teleopHighMade -= 1; + teleopHighAttempt -= 1; + displayHighMade(teleopHighMade); + } + } + + public void increaseHighMadeInput(View view) { + if (teleopHighMade <= 800) { + teleopHighMade += 1; + teleopHighAttempt += 1; + displayHighMade(teleopHighMade); + + } + } + + private void displayHighMade(int number) { + teleopHighMadeInput.setText("" + number); + } + + //Teleop Low Missed + + public void decreaseLowAttempt(View view) { + if (teleopLowMissed != 0) { + teleopLowMissed -= 1; + teleopLowAttempt -= 1; + + displayLowAttemptInput(teleopLowMissed); + } + } + + public void increaseLowAttempt(View view) { + if (teleopLowMissed <= 100) { + teleopLowMissed += 1; + teleopLowAttempt += 1; + displayLowAttemptInput(teleopLowMissed); + } + } + + private void displayLowAttemptInput(int number) { + teleopLowAttemptInput.setText("" + number); + } + + //Teleop trap shots + public void decreaseTrapAttempt(View view) { + if (teleopTrapMissed != 0) { + teleopTrapMissed -= 1; + teleopTrapAttempt -=1; + + displayTrapAttemptInput(teleopTrapMissed); + } + } + + public void increaseTrapAttempt(View view) { + if (teleopTrapMissed <= 800) { + teleopTrapMissed += 1; + teleopTrapAttempt += 1; + displayTrapAttemptInput(teleopTrapMissed); + } + } + + private void displayTrapAttemptInput(int number) { + teleopTrapAttemptsInput.setText("" + number); + } + + //Teleop Trap Made + public void decreaseTrapMadeInput(View view) { + if (teleopTrapMade != 0) { + teleopTrapMade -= 1; + teleopTrapAttempt -= 1; + displayTrapMade(teleopTrapMade); + } + } + + public void increaseTrapMadeInput(View view) { + if (teleopTrapMade <= 800) { + teleopTrapMade += 1; + teleopTrapAttempt += 1; + displayTrapMade(teleopTrapMade); + + } + } + + private void displayTrapMade(int number) { + teleopTrapMadeInput.setText("" + number); + } + //Teleop Low Made + + public void decreaseLowMadeInput(View view) { + if (teleopLowMade != 0) { + teleopLowMade -= 1; + teleopLowAttempt -=1; + displayLowMadeInput(teleopLowMade); + } + } + + public void increaseLowMadeInput(View view) { + if (teleopLowMade <= 800) { + teleopLowMade += 1; + teleopLowAttempt +=1; + + displayLowMadeInput(teleopLowMade); + + } + } + + private void displayLowMadeInput(int number) { + teleopLowMadeInput.setText("" + number); + } + + + // this method sets up a string for a group of checkBoxes + + public void setString(View view) { + boolean checked = ((CheckBox) view).isChecked(); + String s1; + + switch (view.getId()) { + case R.id.observe_Power_Cell_Pickup: + s1 = observPowerCellPickup.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_died_back: + s1 = observDiedBack.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_died_mid: + s1 = observDiedMid.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_dns: + s1 = observDns.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_fast: + s1 = observFast.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_fell_apart: + s1 = observFellApart.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_fell_over: + s1 = observFellOver.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.control_panel_issues: + s1 = observPanelIssues.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_jerky: + s1 = observJerky.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_not_much: + s1 = observNotMuch.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_penalties: + s1 = observPenalties.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_played_defense: + s1 = observPlayedDefense.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_slow: + s1 = observSlow.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_slowed_by_robot: + s1 = observSlowedByRobot.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_smooth: + s1 = observsmooth.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_average_speed: + s1 = observAverageSpeed.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + case R.id.observ_power_cell_stuck_intake: + s1 = observPowerCellStuckIntake.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; +// case R.id.observ_hung_up_power_cell: +// s1 = observHungUpPowerCell.getText().toString() + " ,"; +// if (checked) { +// if (observations.isEmpty()) { +// observations = s1; +// } else { +// observations = observations + s1; +// } +// } else { +// if (observations.contains(s1)) { +// int start = observations.indexOf(s1); +// observations = observations.substring(0, start) + observations.substring(start + s1.length()); +// } +// } +// break; +// case R.id.observ_fell_off_switch: +// s1 = observFellOffSwitch.getText().toString() + " ,"; +// if (checked) { +// if (observations.isEmpty()) { +// observations = s1; +// } else { +// observations = observations + s1; +// } +// } else { +// if (observations.contains(s1)) { +// int start = observations.indexOf(s1); +// observations = observations.substring(0, start) + observations.substring(start + s1.length()); +// } +// } +// break; + case R.id.observ_hung_up: + s1 = observHungUp.getText().toString() + " ,"; + if (checked) { + if (observations.isEmpty()) { + observations = s1; + } else { + observations = observations + s1; + } + } else { + if (observations.contains(s1)) { + int start = observations.indexOf(s1); + observations = observations.substring(0, start) + observations.substring(start + s1.length()); + } + } + break; + } + } + + /*public void setTypeOfBotString(View view) { this is the original line of code before I copied and modified the following on 2/15/2020 ATB*/ + public void setStringTypeBot(View view) { + boolean checked = ((CheckBox) view).isChecked(); + String s1; + + switch (view.getId()) { + case R.id.type_high_shooter: + s1 = typeHighShooter.getText().toString() + " ,"; + if (checked) { + if (typeOfBot.isEmpty()) { + typeOfBot = s1; + } else { + typeOfBot = typeOfBot + s1; + } + } else { + if (typeOfBot.contains(s1)) { + int start = typeOfBot.indexOf(s1); + typeOfBot = typeOfBot.substring(0, start) + typeOfBot.substring(start + s1.length()); + } + } + break; + case R.id.type_low_shooter: + s1 = typeLowShooter.getText().toString() + " ,"; + if (checked) { + if (typeOfBot.isEmpty()) { + typeOfBot = s1; + } else { + typeOfBot = typeOfBot + s1; + } + } else { + if (typeOfBot.contains(s1)) { + int start = typeOfBot.indexOf(s1); + typeOfBot = typeOfBot.substring(0, start) + typeOfBot.substring(start + s1.length()); + } + } + break; + case R.id.type_feeder_bot: + s1 = typeFeederBot.getText().toString() + " ,"; + if (checked) { + if (typeOfBot.isEmpty()) { + typeOfBot = s1; + } else { + typeOfBot = typeOfBot + s1; + } + } else { + if (typeOfBot.contains(s1)) { + int start = typeOfBot.indexOf(s1); + typeOfBot = typeOfBot.substring(0, start) + typeOfBot.substring(start + s1.length()); + } + } + break; + case R.id.type_control_panel: + s1 = typeControlPanel.getText().toString() + " ,"; + if (checked) { + if (typeOfBot.isEmpty()) { + typeOfBot = s1; + } else { + typeOfBot = typeOfBot + s1; + } + } else { + if (typeOfBot.contains(s1)) { + int start = typeOfBot.indexOf(s1); + typeOfBot = typeOfBot.substring(0, start) + typeOfBot.substring(start + s1.length()); + } + } + break; + case R.id.type_counter_defense_bot: + s1 = typeCounterDefenseBot.getText().toString() + " ,"; + if (checked) { + if (typeOfBot.isEmpty()) { + typeOfBot = s1; + } else { + typeOfBot = typeOfBot + s1; + } + } else { + if (typeOfBot.contains(s1)) { + int start = typeOfBot.indexOf(s1); + typeOfBot = typeOfBot.substring(0, start) + typeOfBot.substring(start + s1.length()); + } + } + break; + case R.id.type_defense_bot: + s1 = typeDefenseBot.getText().toString() + " ,"; + if (checked) { + if (typeOfBot.isEmpty()) { + typeOfBot = s1; + } else { + typeOfBot = typeOfBot + s1; + } + } else { + if (typeOfBot.contains(s1)) { + int start = typeOfBot.indexOf(s1); + typeOfBot = typeOfBot.substring(0, start) + typeOfBot.substring(start + s1.length()); + } + } + break; + } + } + + public void setStringShot(View view) { + boolean checked = ((CheckBox) view).isChecked(); + String s1; + + switch (view.getId()) { + case R.id.tele_shoot_target_zone: + s1 = teleShootTargetZone.getText().toString() + " ,"; + if (checked) { + if (shotFrom.isEmpty()) { + shotFrom = s1; + } else { + shotFrom = shotFrom + s1; + } + } else { + if (shotFrom.contains(s1)) { + int start = shotFrom.indexOf(s1); + shotFrom = shotFrom.substring(0, start) + shotFrom.substring(start + s1.length()); + } + } + break; + case R.id.tele_shoot_field_front: + s1 = teleShootFieldFront.getText().toString() + " ,"; + if (checked) { + if (shotFrom.isEmpty()) { + shotFrom = s1; + } else { + shotFrom = shotFrom + s1; + } + } else { + if (shotFrom.contains(s1)) { + int start = shotFrom.indexOf(s1); + shotFrom = shotFrom.substring(0, start) + shotFrom.substring(start + s1.length()); + } + } + break; + case R.id.tele_shoot_field_diagonal: + s1 = teleShootFieldDiagonal.getText().toString() + " ,"; + if (checked) { + if (shotFrom.isEmpty()) { + shotFrom = s1; + } else { + shotFrom = shotFrom + s1; + } + } else { + if (shotFrom.contains(s1)) { + int start = shotFrom.indexOf(s1); + shotFrom = shotFrom.substring(0, start) + shotFrom.substring(start + s1.length()); + } + } + break; + case R.id.tele_shoot_trench_near: + s1 = teleShootTrenchNear.getText().toString() + " ,"; + if (checked) { + if (shotFrom.isEmpty()) { + shotFrom = s1; + } else { + shotFrom = shotFrom + s1; + } + } else { + if (shotFrom.contains(s1)) { + int start = shotFrom.indexOf(s1); + shotFrom = shotFrom.substring(0, start) + shotFrom.substring(start + s1.length()); + } + } + break; + case R.id.tele_shoot_trench_far: + s1 = teleShootTrenchFar.getText().toString() + " ,"; + if (checked) { + if (shotFrom.isEmpty()) { + shotFrom = s1; + } else { + shotFrom = shotFrom + s1; + } + } else { + if (shotFrom.contains(s1)) { + int start = shotFrom.indexOf(s1); + shotFrom = shotFrom.substring(0, start) + shotFrom.substring(start + s1.length()); + } + } + break; + case R.id.tele_shoot_other: + s1 = teleShootOther.getText().toString() + " ,"; + if (checked) { + if (shotFrom.isEmpty()) { + shotFrom = s1; + } else { + shotFrom = shotFrom + s1; + } + } else { + if (shotFrom.contains(s1)) { + int start = shotFrom.indexOf(s1); + shotFrom = shotFrom.substring(0, start) + shotFrom.substring(start + s1.length()); + } + } + break; + } + } + + + /*This method will look at all of the text/number input fields and set error + *for validation of data entry + */ + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { + if (keyCode != KeyEvent.KEYCODE_SPACE && keyCode != KeyEvent.KEYCODE_TAB) { + TextInputEditText inputEditText = (TextInputEditText) v; + + if (inputEditText != null) { + + switch (inputEditText.getId()) { + + case R.id.teleop_high_attempts_input: + teleopHighAttemptInputLayout.setError(null); + break; + + case R.id.teleop_high_made_input: + teleopHighMadeInputLayout.setError(null); + break; + + case R.id.teleop_low_attempt_input: + teleopLowAttemptInputLayout.setError(null); + break; + + case R.id.teleop_low_made_input: + teleopLowMadeInputLayout.setError(null); + break; + + } + } + } + return false; + } + + /* + * This method will verify that all fields are filled and highlight error to user + * along with change focus to first blank input area. The radio button values are obtained + * A file is created on the dvice to send the data to. We add the teleop data to the arraylist + * delimited by commas. We create our message by concatenating the teleop data to the end of + * the auton data. The data is then output to the file we created. We send a message to the user + * about the saved message. We send a result back to the auton activity upon completion. + * We then clear the data of the teleop activity and finish it to close and return + * to the auton activty to clear its data*/ + + public void saveData(View view) throws IOException { + String state = Environment.getExternalStorageState(); + boolean allInputsPassed = false; + + if (StringUtils.isEmptyOrNull(getTextInputLayoutString(teleopHighAttemptInputLayout))) { + teleopHighAttemptInputLayout.setError(getText(R.string.teleopCargoShipHatchPanelError)); + ViewUtils.requestFocus(teleopHighAttemptInputLayout, this); + } else if (endGameLocationSpinner.getSelectedItem().toString().isEmpty()){ + setSpinnerError(endGameLocationSpinner, "Please select an end game location."); + } else if (StringUtils.isEmptyOrNull(getTextInputLayoutString(teleopHighMadeInputLayout))) { + teleopHighMadeInputLayout.setError(getText(R.string.teleopCargoInCargoShipError)); + ViewUtils.requestFocus(teleopHighMadeInputLayout, this); + } else if (StringUtils.isEmptyOrNull(getTextInputLayoutString(teleopLowAttemptInputLayout))) { + teleopLowAttemptInputLayout.setError(getText(R.string.hatchPanelTopError)); + ViewUtils.requestFocus(teleopLowAttemptInputLayout, this); + } else if (StringUtils.isEmptyOrNull(getTextInputLayoutString(teleopLowMadeInputLayout))) { + teleopLowMadeInputLayout.setError(getText(R.string.cargoTopError)); + ViewUtils.requestFocus(teleopLowMadeInputLayout, this); + } /*else if(typeOfBotSpinner.getSelectedItem().toString( ).equals("")){ + + setSpinnerError(typeOfBotSpinner,"Select bot type"); + ViewUtils.requestFocus(typeOfBotSpinner, this); + + }*/ else { + allInputsPassed = true; + } + if (!allInputsPassed) { + return; + } + + final RadioButton controlPanelRadingRadioBtn = findViewById(controlPanelRadingRadioGroup.getCheckedRadioButtonId()); + final RadioButton counterDefenseEffectivenessRadiobtn = findViewById(counterDefenseEffectiveness.getCheckedRadioButtonId()); + final RadioButton overallEffectivenessRadiobtn = findViewById(overallEffectivenessRadioGoup.getCheckedRadioButtonId()); + final RadioButton trainedDriveTeamRadiobtn = findViewById(trainedDriveTeamRadioGoup.getCheckedRadioButtonId()); + final RadioButton powerCellPickUpRadioBtn = findViewById(powerCellPickupRadioGroup.getCheckedRadioButtonId()); + final RadioButton lowPortDumpRadioBtn = findViewById(lowPortDumpRadioGroup.getCheckedRadioButtonId()); + final RadioButton underTrenchRadioBtn = findViewById(underTrenchRadioGroup.getCheckedRadioButtonId()); + final RadioButton defenseRatingRadioBtn = findViewById(defenseRatingRadioGroup.getCheckedRadioButtonId()); + final RadioButton powerCellPlacementRatingRadioBtn = findViewById(powerCellPlacementRatingRadioGroup.getCheckedRadioButtonId()); + final RadioButton climbTimeRadiobtn = findViewById(climbTimeRadioGroup.getCheckedRadioButtonId()); + final RadioButton cycleTimeRadiobtn = findViewById(cycleTimeRadioGroup.getCheckedRadioButtonId()); + + + + if(PermissionUtils.getPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + if (Environment.MEDIA_MOUNTED.equals(state)) { + File dir = new File(Environment.getExternalStorageDirectory() + "/Scouting"); + dir.mkdirs(); + + File file = new File(dir, "Match" + Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID) + ".csv"); + + teleopDataStringList.add(getTextInputLayoutString(teleopHighAttemptInputLayout)); + teleopDataStringList.add(getTextInputLayoutString(teleopHighMadeInputLayout)); + teleopDataStringList.add(getTextInputLayoutString(teleopLowAttemptInputLayout)); + teleopDataStringList.add(getTextInputLayoutString(teleopLowMadeInputLayout)); + teleopDataStringList.add(getTextInputLayoutString(teleopTrapAttemptInputLayout)); + teleopDataStringList.add(getTextInputLayoutString(teleopTrapMadeInputLayout)); +// teleopDataStringList.add(cycleTimeRadiobtn.getText().toString()); + teleopDataStringList.add(endGameLocationSpinner.getSelectedItem().toString()); + teleopDataStringList.add(climbTimeRadiobtn.getText().toString()); + teleopDataStringList.add(typeOfBot); + teleopDataStringList.add(shotFrom); + teleopDataStringList.add(powerCellPickUpRadioBtn.getText().toString()); +// teleopDataStringList.add(lowPortDumpRadioBtn.getText().toString()); +// teleopDataStringList.add(underTrenchRadioBtn.getText().toString()); + teleopDataStringList.add(defenseRatingRadioBtn.getText().toString()); + teleopDataStringList.add(counterDefenseEffectivenessRadiobtn.getText().toString()); +// teleopDataStringList.add(powerCellPlacementRatingRadioBtn.getText().toString()); +// teleopDataStringList.add(controlPanelRadingRadioBtn.getText().toString()); + + // teleopDataStringList.add(cycleTimeSpinner.getSelectedItem().toString()); + teleopDataStringList.add(overallEffectivenessRadiobtn.getText().toString()); + teleopDataStringList.add(trainedDriveTeamRadiobtn.getText().toString()); + + teleopDataStringList.add(observations); + + //teleopDataStringList.add(typeOfBotSpinner.getSelectedItem().toString()); + teleopDataStringList.add(summaryInput.getText().toString()); + teleopDataStringList.add(issuesInput.getText().toString()); + + teleopDataStringList.add(ScouterInitialsActivity.getInitials()); + + String message = auton + "|" + FormatStringUtils.addDelimiter(teleopDataStringList, "|") + "\n"; + + try { + FileOutputStream fileOutputStream = new FileOutputStream(file, true); + fileOutputStream.write(message.getBytes()); + fileOutputStream.close(); + + Toast.makeText(getApplicationContext(), "Saved!", Toast.LENGTH_LONG).show(); + } catch (IOException e) { + Toast.makeText(getApplicationContext(), "IOException! Go talk to the programmers!", Toast.LENGTH_LONG).show(); + Log.d("Scouting", e.getMessage()); + } + } else { + Toast.makeText(getApplicationContext(), "SD card not found", Toast.LENGTH_LONG).show(); + } + + Intent intent = getIntent(); + intent.putExtra("Key", value); + setResult(RESULT_OK, intent); + + clearData(view); + + finish(); + } + + teleopHighAttemptInputLayout.setError(null); + teleopHighMadeInput.setError(null); + teleopLowAttemptInputLayout.setError(null); + teleopLowMadeInputLayout.setError(null); + + + } + + /*The method will clear all the data in the text fields, checkboxes, and + * set radio buttons to default*/ + public void clearData(View view) { + teleopHighAttemptsInput.setText("" + teleopHighMissed); + teleopHighMadeInput.setText("" + teleopHighMade); + teleopLowAttemptInput.setText("" + teleopLowMissed); + teleopLowMadeInput.setText("" + teleopLowMade); + + controlPanelRadingRadioGroup.clearCheck(); + counterDefenseEffectiveness.clearCheck(); + endGameLocationSpinner.setSelection(0); + climbTimeRadioGroup.clearCheck(); + //cycleTimeSpinner.setSelection(0); + cycleTimeRadioGroup.clearCheck(); + defenseRatingRadioGroup.clearCheck(); + powerCellPlacementRatingRadioGroup.clearCheck(); + overallEffectivenessRadioGoup.clearCheck(); + trainedDriveTeamRadioGoup.clearCheck(); + powerCellPickupRadioGroup.clearCheck(); + lowPortDumpRadioGroup.clearCheck(); + underTrenchRadioGroup.clearCheck(); + observsmooth.setChecked(false); + observSlowedByRobot.setChecked(false); + observSlow.setChecked(false); + observPlayedDefense.setChecked(false); + observPenalties.setChecked(false); + observNotMuch.setChecked(false); + observJerky.setChecked(false); + observPanelIssues.setChecked(false); + observFellOver.setChecked(false); + observFellApart.setChecked(false); + observFast.setChecked(false); + observDns.setChecked(false); + observDiedMid.setChecked(false); + observDiedBack.setChecked(false); + observPowerCellPickup.setChecked(false); + observAverageSpeed.setChecked(false); + observPowerCellStuckIntake.setChecked(false); +// observHungUpPowerCell.setChecked(false); +// observFellOffSwitch.setChecked(false); + observHungUp.setChecked(false); + typeLowShooter.setChecked(false); + typeFeederBot.setChecked(false); + typeControlPanel.setChecked(false); + typeCounterDefenseBot.setChecked(false); + typeDefenseBot.setChecked(false); + teleShootTargetZone.setChecked(false); + teleShootFieldFront.setChecked(false); + teleShootFieldDiagonal.setChecked(false); + teleShootTrenchNear.setChecked(false); + teleShootTrenchFar.setChecked(false); + teleShootOther.setChecked(false); + // typeOfBotSpinner.setSelection(0); + summaryInput.setText(null); + issuesInput.setText(null); + teleopHighAttempt = 0; + teleopHighMissed =0; + teleopHighMade = 0; + teleopLowAttempt = 0; + teleopLowMissed = 0; + teleopLowMade = 0; + + } + + /* This method will change the text entered into the app into a string if it is not already*/ + private String getTextInputLayoutString(@NonNull TextInputLayout textInputLayout) { + final EditText editText = textInputLayout.getEditText(); + return editText != null && editText.getText() != null ? editText.getText().toString() : ""; + } +} diff --git a/app/src/main/java/com/example/ncgears/scouting/customToast/CustomToast.java b/app/src/main/java/com/example/ncgears/scouting/customToast/CustomToast.java new file mode 100644 index 0000000..709287f --- /dev/null +++ b/app/src/main/java/com/example/ncgears/scouting/customToast/CustomToast.java @@ -0,0 +1,55 @@ +package com.example.ncgears.scouting.customToast; + +import android.app.Activity; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.ncgears.scouting.R; + +public class CustomToast{ + + private static Toast currentToast; + + public static void showShort(Context context, String message){ + if(currentToast != null) currentToast.cancel(); + LayoutInflater inflater = ((Activity)context).getLayoutInflater(); + View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) ((Activity) context).findViewById(R.id.root)); + TextView text = (TextView) layout.findViewById(R.id.message); + + text.setText(message); + + Toast toast = new Toast(context); + + toast.setDuration(Toast.LENGTH_SHORT); + + toast.setView(layout); + toast.show(); + currentToast = toast; + } + + public static void showLong(Context context, String message){ + if(currentToast != null) currentToast.cancel(); + LayoutInflater inflater = ((Activity)context).getLayoutInflater(); + View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) ((Activity) context).findViewById(R.id.root)); + TextView text = (TextView) layout.findViewById(R.id.message); + + text.setText(message); + + Toast toast = new Toast(context); + + toast.setDuration(Toast.LENGTH_LONG); + + toast.setView(layout); + toast.show(); + currentToast = toast; + } + + public static Toast getCurrentToast(){ + return currentToast; + } + +} diff --git a/app/src/main/java/com/example/ncgears/scouting/data/GetJasonData.java b/app/src/main/java/com/example/ncgears/scouting/data/GetJasonData.java new file mode 100644 index 0000000..0c1bc93 --- /dev/null +++ b/app/src/main/java/com/example/ncgears/scouting/data/GetJasonData.java @@ -0,0 +1,112 @@ +package com.example.ncgears.scouting.data; + +import android.content.ContentValues; +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.os.AsyncTask; + +import com.example.ncgears.scouting.MainActivity; +import com.example.ncgears.scouting.settings.settings.SettingsEntry; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; + + +public class GetJasonData extends AsyncTask{ + + Context ctx; + String data = ""; + String dataParsed = ""; + String singleParsed = ""; + String[] teams; + + + public GetJasonData(Context ctx){ + + this.ctx = ctx; + + } + + + @Override + protected Void doInBackground(Void... voids) { + + + + try { + URL url = new URL(SettingsEntry.teamsUrl); + + HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); + InputStream inputStream = httpURLConnection.getInputStream(); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); + + String line = ""; + + while (line != null){ + + line = bufferedReader.readLine(); + data = data + line; + } + + JSONObject JO = new JSONObject(data); + JSONArray JA = JO.getJSONArray("valueRanges"); + JSONObject Jobj = new JSONObject(JA.getString(0)); + JSONArray Jarr = Jobj.getJSONArray("values"); + + TeamsDbHelper mDbHelper = new TeamsDbHelper(ctx); + SQLiteDatabase db = mDbHelper.getWritableDatabase(); + ContentValues values = new ContentValues(); + + + for(int i = 0; i < Jarr.length(); i++){ + + + String teamNumber = Jarr.getJSONArray(i).getString(0); + String teamName = Jarr.getJSONArray(i).getString(1); + singleParsed = singleParsed + teamNumber + " | " + teamName + "\n"; + values.put(TeamsContract.TeamEntry.COLUMN_TEAM_NUMBER, teamNumber); + values.put(TeamsContract.TeamEntry.COLUMN_TEAM_NAME, teamName); + TeamsDbHelper.setTeams(db, values); + } + + + + db.close(); + + + + + } catch (MalformedURLException e){ + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + + return null; + } + + + + @Override + protected void onPostExecute(Void aVoid){ + super.onPostExecute(aVoid); + + + MainActivity.data.setText(singleParsed); + + + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ncgears/scouting/data/TeamsContract.java b/app/src/main/java/com/example/ncgears/scouting/data/TeamsContract.java new file mode 100644 index 0000000..b878981 --- /dev/null +++ b/app/src/main/java/com/example/ncgears/scouting/data/TeamsContract.java @@ -0,0 +1,22 @@ +package com.example.ncgears.scouting.data; + +import android.provider.BaseColumns; + +public class TeamsContract { + + private TeamsContract(){} + + public static final class TeamEntry implements BaseColumns { + + // constant variable with Table Name + public static final String TABLE_NAME = "teams"; + + // constant variables of column names + public static final String _ID = BaseColumns._ID; + public static final String COLUMN_TEAM_NUMBER = "team_number"; + public static final String COLUMN_TEAM_NAME = "team_name"; + + + } + +} diff --git a/app/src/main/java/com/example/ncgears/scouting/data/TeamsDbHelper.java b/app/src/main/java/com/example/ncgears/scouting/data/TeamsDbHelper.java new file mode 100644 index 0000000..c7c1cfb --- /dev/null +++ b/app/src/main/java/com/example/ncgears/scouting/data/TeamsDbHelper.java @@ -0,0 +1,129 @@ +package com.example.ncgears.scouting.data; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; + +import com.example.ncgears.scouting.data.TeamsContract.TeamEntry; + +import java.util.ArrayList; + + +public class TeamsDbHelper extends SQLiteOpenHelper { + + public static final String TAG = TeamsDbHelper.class.getSimpleName(); + private static final String DATABASE_NAME = "teams.db"; + private static final int DATABASE_VERSION = 1; + + + public TeamsDbHelper(Context context){ + super(context, DATABASE_NAME, null, DATABASE_VERSION); + + Log.d(TAG, "TeamsDbHelper: Database Created."); + } + + + + @Override + public void onCreate(SQLiteDatabase db) { + + createTable(db); + + } + + public static void createTable(SQLiteDatabase db){ + + String sql_create_teams_table = "CREATE TABLE "+ TeamEntry.TABLE_NAME +"(" + + TeamEntry._ID +" Integer PRIMARY KEY AUTOINCREMENT, " + + TeamEntry.COLUMN_TEAM_NUMBER +" text NOT NULL, " + + TeamEntry.COLUMN_TEAM_NAME +" text);"; + + db.execSQL(sql_create_teams_table); + + } + + public static void dropTable(SQLiteDatabase db){ + + + + String sql_drop_table = "DROP TABLE if EXISTS " + TeamsContract.TeamEntry.TABLE_NAME + ";"; + + + db.execSQL(sql_drop_table); + + + + + } + + + public static void setTeams(SQLiteDatabase db, ContentValues values){ + + + long newIndex = db.insert(TeamsContract.TeamEntry.TABLE_NAME, null, values); + + } + + public static ArrayList getTeamNumbers(SQLiteDatabase db){ + + ArrayList result = new ArrayList(); + + Cursor cursor = db.rawQuery("SELECT "+ TeamEntry.COLUMN_TEAM_NUMBER + " FROM teams;",null); + + int numberColumn = cursor.getColumnIndex(TeamEntry.COLUMN_TEAM_NUMBER); + + cursor.moveToFirst(); + + if(cursor != null && (cursor.getCount() > 0)){ + + int i = 0; + + do { + + result.add(cursor.getString(numberColumn)); + + }while (cursor.moveToNext()); + + } + + return result; + + } + + public static ArrayList getTeams(SQLiteDatabase db){ + + ArrayList result = new ArrayList(); + + Cursor cursor = db.rawQuery("SELECT * FROM teams;",null); + + int numberColumn = cursor.getColumnIndex(TeamEntry.COLUMN_TEAM_NUMBER); + int nameColumn = cursor.getColumnIndex(TeamEntry.COLUMN_TEAM_NAME); + + cursor.moveToFirst(); + + if(cursor != null && (cursor.getCount() > 0)){ + + int i = 0; + + do { + + result.add(cursor.getString(numberColumn) + " | " + cursor.getString(nameColumn)); + + }while (cursor.moveToNext()); + + } + + return result; + + } + + @Override + public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { + + } + + +} \ No newline at end of file diff --git a/app/src/main/java/utils/FormatStringUtils.java b/app/src/main/java/utils/FormatStringUtils.java new file mode 100644 index 0000000..8845e81 --- /dev/null +++ b/app/src/main/java/utils/FormatStringUtils.java @@ -0,0 +1,23 @@ +package utils; + +import java.util.ArrayList; + + + +public class FormatStringUtils { + + public static String addDelimiter(ArrayList strings, String delimiter) { + + final StringBuilder stringBuilder = new StringBuilder(); + + for (int i = 0; i < strings.size(); i++) { + stringBuilder.append(strings.get(i)); + + if (i < strings.size() - 1) { + stringBuilder.append(delimiter); + } + } + + return stringBuilder.toString(); + } +} \ No newline at end of file diff --git a/app/src/main/java/utils/PermissionUtils.java b/app/src/main/java/utils/PermissionUtils.java new file mode 100644 index 0000000..dbdb3c3 --- /dev/null +++ b/app/src/main/java/utils/PermissionUtils.java @@ -0,0 +1,16 @@ +package utils; + +import android.app.Activity; +import android.content.pm.PackageManager; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; + +public class PermissionUtils { + public static boolean getPermissions(Activity activity, String type) { + int permission = ContextCompat.checkSelfPermission(activity, type); + if (permission != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(activity, new String[]{type}, 1); + } + return permission == PackageManager.PERMISSION_GRANTED; + } +} diff --git a/app/src/main/java/utils/StringUtils.java b/app/src/main/java/utils/StringUtils.java new file mode 100644 index 0000000..e377ab1 --- /dev/null +++ b/app/src/main/java/utils/StringUtils.java @@ -0,0 +1,7 @@ +package utils; + +public class StringUtils { + public static boolean isEmptyOrNull(String string){ + return string == null || string.isEmpty(); + } +} \ No newline at end of file diff --git a/app/src/main/java/utils/ViewUtils.java b/app/src/main/java/utils/ViewUtils.java new file mode 100644 index 0000000..de5bc1b --- /dev/null +++ b/app/src/main/java/utils/ViewUtils.java @@ -0,0 +1,15 @@ +package utils; + +import android.app.Activity; +import android.view.View; +import android.view.WindowManager; + +public class ViewUtils { + public static boolean requestFocus(View v, Activity activity){ + if(v.requestFocus()){ + activity.getWindow().setSoftInputMode((WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)); + return true; + } + return false; + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/custom_toast.xml b/app/src/main/res/drawable/custom_toast.xml new file mode 100644 index 0000000..5d64170 --- /dev/null +++ b/app/src/main/res/drawable/custom_toast.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..2408e30 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_auton.xml b/app/src/main/res/layout/activity_auton.xml new file mode 100644 index 0000000..d79c7bd --- /dev/null +++ b/app/src/main/res/layout/activity_auton.xml @@ -0,0 +1,516 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + // Begin of High Power Port counters + + + + + + + + + + + + + + + + + + +