Skip to content

Commit

Permalink
Merge pull request #1 from 1595Dragons/development
Browse files Browse the repository at this point in the history
2.0.1
  • Loading branch information
yeSpud authored Mar 3, 2019
2 parents 6d5dded + 0c289db commit 58de483
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 64 deletions.
6 changes: 3 additions & 3 deletions AndroidApp/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "org.dragons.Dragons.scoutingapp"
applicationId "org.dragons.scoutingapp"
minSdkVersion 19
targetSdkVersion 28
versionCode 5
versionName '2.0'
versionCode 6
versionName '2.0.1'
}
buildTypes {
release {
Expand Down
2 changes: 1 addition & 1 deletion AndroidApp/app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2},"path":"app-release.apk","properties":{"packageId":"org.dragons.Dragons.scoutingapp","split":"","minSdkVersion":"19"}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":6,"versionName":"2.0.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;


/**
Expand Down Expand Up @@ -93,7 +94,7 @@ public void onCreate(android.os.Bundle savedInstanceState) {
// Add the teleop header
contentView.addView(this.generateTextView("TeleOp:", 20,
this.createLayoutParameters(LinearLayout.LayoutParams.MATCH_PARENT, 0,
40, 0)));
100, 0)));

// Add the stuff for teleop
try {
Expand All @@ -104,11 +105,11 @@ public void onCreate(android.os.Bundle savedInstanceState) {
new error_activity().new CatchError().Catch(this, noConfig);
}


// Add the end game header
contentView.addView(this.generateTextView("End game:", 20,
this.createLayoutParameters(LinearLayout.LayoutParams.MATCH_PARENT, 0,
40, 0)));
100, 0)));


// Add end game stuff
try {
Expand All @@ -119,11 +120,10 @@ public void onCreate(android.os.Bundle savedInstanceState) {
new error_activity().new CatchError().Catch(this, noConfig);
}


// Comment section time
contentView.addView(this.generateTextView("Additional feedback:", 20,
this.createLayoutParameters(LinearLayout.LayoutParams.MATCH_PARENT, 0,
20, 0)));
100, 0)));

// Comments
final EditText comments = new EditText(this);
Expand Down Expand Up @@ -331,17 +331,14 @@ private LinearLayout generateNumberPicker(String title, int minValue, int maxVal
* Create and return a RadioButton.
*
* @param text The text of the RadioButton.
* @param isChecked Whether or not the RadioButton is checked by default.
* @param layoutParameters The LayoutParameters.
* @return The RadioButton.
*/
private RadioButton generateRadioButton(String text, boolean isChecked, LinearLayout.LayoutParams layoutParameters) {
private RadioButton generateRadioButton(String text, LinearLayout.LayoutParams layoutParameters) {
Log.d("text", text);
Log.d("isChecked", Boolean.toString(isChecked));
RadioButton button = new RadioButton(this);
button.setText(text);
button.setTextSize(15);
button.setChecked(isChecked);
button.setHighlightColor(Color.LTGRAY);
button.setBackgroundColor(Color.GRAY);
button.setTextColor(Color.WHITE);
Expand Down Expand Up @@ -407,16 +404,22 @@ private void parseData(org.frc1595Dragons.scoutingapp.MatchFiles.MatchBase match
RadioGroup group = new RadioGroup(this);
try {
JSONObject radioButtons = new JSONObject(match.value.get(0));
while (radioButtons.keys().hasNext()) {
String key = radioButtons.keys().next();
group.addView(this.generateRadioButton(key, Boolean.parseBoolean(radioButtons.get(key).toString()),
this.createLayoutParameters(LinearLayout.LayoutParams.MATCH_PARENT,
0, 5, 0)));
Log.d("Radio buttons", radioButtons.toString());
Iterator<String> keys = radioButtons.keys();
while (keys.hasNext()) {
String key = keys.next();
RadioButton button = this.generateRadioButton(key, this.createLayoutParameters(LinearLayout.LayoutParams.MATCH_PARENT,
0, 5, 0));
group.addView(button);
if (Boolean.parseBoolean(radioButtons.optString(key))) {
group.check(button.getId());
}
}
} catch (JSONException e) {
new error_activity().new CatchError().Catch(this, e);
return;
}

contentView.addView(group);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import org.frc1595Dragons.scoutingapp.BlueFiles.Bluetooth;
import org.frc1595Dragons.scoutingapp.R;

Expand All @@ -19,7 +19,7 @@
* Created by Stephen Ogden on 3/23/17.
* FRC 1595
*/
public class main_activity extends android.support.v7.app.AppCompatActivity {
public class main_activity extends AppCompatActivity {

private android.widget.Button StartScouting, Disconnect, Connect;

Expand All @@ -43,14 +43,14 @@ protected void onCreate(android.os.Bundle savedInstance) {
this.StartScouting.setOnClickListener((event) -> {
try {
if (Bluetooth.MAC != null && !Bluetooth.MAC.equals("") && Bluetooth.matchData != null) {
if (Bluetooth.matchData.autonomousData != null && Bluetooth.matchData.teleopData != null && Bluetooth.matchData.endgameData != null) {
if (Bluetooth.hasMatchData) {
this.startScouting().show();
} else {
Toast.makeText(this, "Config still being loaded. Try again in a few seconds.", Toast.LENGTH_LONG).show();
}
}
} catch (NullPointerException NPE) {
Toast.makeText(this, "Config still being loaded. Try again in a few seconds.", Toast.LENGTH_LONG).show();
Toast.makeText(this, "Config still needs to be sent. Try again in a few seconds.", Toast.LENGTH_LONG).show();
}
});

Expand Down Expand Up @@ -88,10 +88,9 @@ protected void onCreate(android.os.Bundle savedInstance) {
boolean bluetoothEnabled = Bluetooth.isBluetoothOn();
android.util.Log.d("Bluetooth enabled", Boolean.toString(bluetoothEnabled));
if (!bluetoothEnabled) {
new error_activity().new CatchError().Catch(this, new Exception("Bluetooth is not supported/enabled on this device"));
Toast.makeText(this, "Bluetooth is not currently enabled. Please enable Bluetooth and restart the app.", Toast.LENGTH_LONG).show();
this.Connect.setVisibility(View.GONE);
}


}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.bluetooth.BluetoothSocket;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
Expand Down Expand Up @@ -72,6 +73,7 @@ public void run() {
Log.d("Validated object", "Config");
JSONObject config = object.getJSONObject(Request.Requests.CONFIG.name());
Bluetooth.setMatchData(config);
Bluetooth.hasMatchData = true;
break;
case REQUEST_PING:
Log.d("Validated object", "Requested ping");
Expand Down Expand Up @@ -111,8 +113,6 @@ public void run() {
e.printStackTrace();
}
}


}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import org.frc1595Dragons.scoutingapp.Activities.main_activity;
import org.frc1595Dragons.scoutingapp.MatchFiles.Match;
import org.frc1595Dragons.scoutingapp.MatchFiles.MatchBase;
import org.json.JSONObject;

import java.io.IOException;
Expand All @@ -20,12 +22,14 @@ public class Bluetooth {
/**
* Bluetooth adapter (think of it as the specific microchip on the phone).
*/
public final static BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
public static BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();

public static String MAC;

public static Match matchData = new Match();

public static boolean hasMatchData = false;

public static Bluethread bluetoothConnection;

/**
Expand Down Expand Up @@ -82,26 +86,12 @@ public static void close() throws IOException {
* @return Whether or not bluetooth is enabled on this device.
*/
public static boolean isBluetoothOn() {
boolean isOn;

// Intent in case we can request the user to turn on bluetooth.
Intent turnOnBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
try {
// Check of the adapter is enabled or not
isOn = btAdapter.isEnabled();
} catch (Exception NullPointerException) {
// If its null, one cause is that its just turned off, so try re-enabling it
// Prompt user to turn on Bluetooth
AppCompatActivity activity = new AppCompatActivity();
try {
activity.startActivityForResult(turnOnBluetooth, 1);
} catch (NullPointerException NPE) {
return false;
}
isOn = btAdapter.isEnabled();
return Bluetooth.btAdapter.isEnabled();
} catch (Exception e) {
return false;
}

return isOn;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.lang.NullPointerException;
import java.util.ArrayList;
import java.util.Iterator;

/**
* Created by Stephen Ogden on 12/24/18.
Expand Down Expand Up @@ -32,42 +33,37 @@ public class Match {
* @param rawData The JSON object data.
* @param size The size of the data.
* @return The match data. This still needs to be converted to either Autonomous, TeleOp, or Endgame data.
* @throws org.json.JSONException Throws a JSONException if there is an error parsing the JSON data.
* @throws NullPointerException Throws a NullPointerException if some data is null and shouldn't be.
*/
public static MatchBase[] getMatchData(org.json.JSONObject rawData, int size) throws org.json.JSONException, NullPointerException {
public static MatchBase[] getMatchData(org.json.JSONObject rawData, int size) {

MatchBase[] fullMatchData = new MatchBase[size];

// Replace all the fancy JSON crap.
String[] keys = rawData.names().toString().replace("[", "").replace("]", "").replace("\"", "").split(",");
Log.d("Keys", java.util.Arrays.toString(keys));
for (int i = 0; i < size; i++) {
String key = keys[i];
// Get and iterate over the keys in the data
Iterator<String> keys = rawData.keys();
int i = 0;
while (keys.hasNext()) {
String key = keys.next().replace("\\", "");
Log.d("Key", key);

org.json.JSONArray jsonArray = rawData.optJSONArray(key);
Log.d("JsonArray", rawData.getJSONArray(key).toString());
Log.d("JsonArray", jsonArray.toString());

MatchBase match = new MatchBase();

match.name = key;
match.datatype = MatchBase.DataType.valueOf(jsonArray.getString(0));

final int jsonArraySize = jsonArray.length();
Log.d("JsonArraySize", Integer.toString(jsonArraySize));
match.datatype = MatchBase.DataType.valueOf(jsonArray.optString(0).replace("\\", ""));

ArrayList<String> values = new ArrayList<>();
for (int k = 1; k < jsonArraySize; k++) {
values.add(jsonArray.getString(k));
Log.d("Value", jsonArray.getString(k));
for (int k = 1; k < jsonArray.length(); k++) {
String ad = jsonArray.optString(k).replace("\\", "");
Log.d("Adding value", ad);
values.add(ad);
}
match.value = values;

fullMatchData[i] = match;

i++;
}

return fullMatchData;
}

Expand Down Expand Up @@ -99,6 +95,7 @@ public static TeleOp[] matchBaseToTeleOp(MatchBase[] matchBase) {
TeleOp[] t = new TeleOp[matchBase.length];
for (int i = 0; i < matchBase.length; i++) {
TeleOp teleop = new Match().new TeleOp();
Log.d("TeleOpName", matchBase[i].name);
teleop.name = matchBase[i].name;
teleop.datatype = matchBase[i].datatype;
teleop.value = matchBase[i].value;
Expand Down
3 changes: 3 additions & 0 deletions AndroidApp/app/src/main/res/layout/data_collection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context=".Activities.data_collection">

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/buttons"
android:layout_alignParentTop="true"
android:background="@color/black"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical"
android:fillViewport="true">
Expand All @@ -31,6 +33,7 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:background="@color/black"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
Expand Down
2 changes: 1 addition & 1 deletion AndroidApp/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
<string name="full_stack_trace">Full stack-trace:</string>

<string name="connected_to_server">Connected to server:</string>
<string name="BuildDate">Build date: 11:16; 2/27/2019</string>
<string name="BuildDate">Build date: 23:10; 3/2/2019</string>
</resources>

0 comments on commit 58de483

Please sign in to comment.