Skip to content

Commit

Permalink
Merge pull request #16 from cmsc436/sample
Browse files Browse the repository at this point in the history
Improved sample app to allow for more robust testing.
  • Loading branch information
krockpot authored Apr 24, 2017
2 parents 67da2be + 8f86e63 commit 7cd5d7b
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 15 deletions.
78 changes: 74 additions & 4 deletions app/src/main/java/edu/umd/sheets436/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -22,19 +25,29 @@ public class MainActivity extends AppCompatActivity implements Sheets.Host {
public static final int LIB_PERMISSION_REQUEST_CODE = 1003;
public static final int LIB_PLAY_SERVICES_REQUEST_CODE = 1004;
public static final int LIB_CONNECTION_REQUEST_CODE = 1005;
private static final int MIN = 0;
private static final int MAX = 100;

private Sheets sheet;
private Spinner spinner;

private double random() {
double range = Math.abs(MAX - MIN);
return (Math.random() * range) + MIN;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

sheet = new Sheets(this, this, getString(R.string.app_name), getString(R.string.CMSC436_testing_spreadsheet), getString(R.string.CMSC436_private_test_spreadsheet));
sheet.writeData(Sheets.TestType.LH_TAP, getString(R.string.user_id), 1.23f);
spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.test_array, android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);

float[] trialData = {1.23f, 4.56f, 7.89f};
sheet.writeTrials(Sheets.TestType.LH_TAP, getString(R.string.user_id), trialData);
sheet = new Sheets(this, this, getString(R.string.app_name), getString(R.string.CMSC436_testing_spreadsheet), getString(R.string.CMSC436_private_test_spreadsheet));

// The next two lines of code allows network calls on the UI thread. Do not do this in a
// real app. I'm just doing this for ease of coding/reading, since this is a sample of how
Expand All @@ -54,6 +67,63 @@ protected void onCreate(Bundle savedInstanceState) {
sheet.uploadToDrive(getString(R.string.CMSC436_test_folder), getString(R.string.image_name), bitmap);
}

public void sendToSheets(View v) {
float f = (float)random();
float[] trialData = {(float)random(), (float)random(), (float)random()};
switch (spinner.getSelectedItem().toString()) {
case "Tap (Hands)":
sheet.writeData(Sheets.TestType.LH_TAP, getString(R.string.user_id), f);
sheet.writeData(Sheets.TestType.RH_TAP, getString(R.string.user_id), f);
sheet.writeTrials(Sheets.TestType.LH_TAP, getString(R.string.user_id), trialData);
sheet.writeTrials(Sheets.TestType.RH_TAP, getString(R.string.user_id), trialData);
break;
case "Tap (Feet)":
sheet.writeData(Sheets.TestType.LF_TAP, getString(R.string.user_id), f);
sheet.writeData(Sheets.TestType.RF_TAP, getString(R.string.user_id), f);
sheet.writeTrials(Sheets.TestType.LF_TAP, getString(R.string.user_id), trialData);
sheet.writeTrials(Sheets.TestType.RF_TAP, getString(R.string.user_id), trialData);
break;
case "Spiral":
sheet.writeData(Sheets.TestType.LH_SPIRAL, getString(R.string.user_id), f);
sheet.writeData(Sheets.TestType.RH_SPIRAL, getString(R.string.user_id), f);
sheet.writeTrials(Sheets.TestType.LH_SPIRAL, getString(R.string.user_id), trialData);
sheet.writeTrials(Sheets.TestType.RH_SPIRAL, getString(R.string.user_id), trialData);
break;
case "Level":
sheet.writeData(Sheets.TestType.LH_LEVEL, getString(R.string.user_id), f);
sheet.writeData(Sheets.TestType.RH_LEVEL, getString(R.string.user_id), f);
sheet.writeTrials(Sheets.TestType.LH_LEVEL, getString(R.string.user_id), trialData);
sheet.writeTrials(Sheets.TestType.RH_LEVEL, getString(R.string.user_id), trialData);
break;
case "Balloon":
sheet.writeData(Sheets.TestType.LH_POP, getString(R.string.user_id), f);
sheet.writeData(Sheets.TestType.RH_POP, getString(R.string.user_id), f);
sheet.writeTrials(Sheets.TestType.LH_POP, getString(R.string.user_id), trialData);
sheet.writeTrials(Sheets.TestType.RH_POP, getString(R.string.user_id), trialData);
break;
case "Curl":
sheet.writeData(Sheets.TestType.LH_CURL, getString(R.string.user_id), f);
sheet.writeData(Sheets.TestType.RH_CURL, getString(R.string.user_id), f);
sheet.writeTrials(Sheets.TestType.LH_CURL, getString(R.string.user_id), trialData);
sheet.writeTrials(Sheets.TestType.RH_CURL, getString(R.string.user_id), trialData);
break;
case "Sway":
sheet.writeData(Sheets.TestType.SWAY_OPEN_APART, getString(R.string.user_id), f);
sheet.writeTrials(Sheets.TestType.SWAY_OPEN_APART, getString(R.string.user_id), trialData);
sheet.writeData(Sheets.TestType.SWAY_OPEN_TOGETHER, getString(R.string.user_id), f);
sheet.writeTrials(Sheets.TestType.SWAY_OPEN_TOGETHER, getString(R.string.user_id), trialData);
sheet.writeData(Sheets.TestType.SWAY_CLOSED, getString(R.string.user_id), f);
sheet.writeTrials(Sheets.TestType.SWAY_CLOSED, getString(R.string.user_id), trialData);
break;
case "Walk (Indoors)":
sheet.writeData(Sheets.TestType.INDOOR_WALKING, getString(R.string.user_id), f);
sheet.writeTrials(Sheets.TestType.INDOOR_WALKING, getString(R.string.user_id), trialData);
break;
default:
break;
}
}

@Override
public void onRequestPermissionsResult (int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
sheet.onRequestPermissionsResult(requestCode, permissions, grantResults);
Expand Down
24 changes: 14 additions & 10 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="edu.umd.sheets436.MainActivity">

<TextView
android:id="@+id/hello_world"
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:gravity="center"
android:onClick="sendToSheets"
android:text="@string/button_text" />


</android.support.constraint.ConstraintLayout>
</LinearLayout>
13 changes: 13 additions & 0 deletions app/src/main/res/values/spinner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="test_array">
<item>Tap (Hands)</item>
<item>Tap (Feet)</item>
<item>Spiral</item>
<item>Level</item>
<item>Balloon</item>
<item>Curl</item>
<item>Sway</item>
<item>Walk (Indoors)</item>
</string-array>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
<string name="CMSC436_test_folder">0B3RViSRC0aoYVDN6MWZUb1RDSVU</string>
<string name="user_id">Your user ID belongs here!</string>
<string name="image_name">The name of your image upload goes here!</string>
<string name="button_text">Send random data to test sheet</string>
</resources>
4 changes: 3 additions & 1 deletion sheets436/src/main/java/edu/umd/cmsc436/sheets/Sheets.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ public enum TestType {
RH_POP("'Balloon Test (RH)'"),
LH_CURL("'Curling Test (LH)'"),
RH_CURL("'Curling Test (RH)'"),
HEAD_SWAY("'Swaying Test'"),
SWAY_OPEN_APART("'Swaying Test (Legs apart eyes open)'"),
SWAY_OPEN_TOGETHER("'Swaying Test (Legs closed eyes open)'"),
SWAY_CLOSED("'Swaying Test (Legs closed eyes closed)'"),
INDOOR_WALKING("'Indoor Walking Test");

private final String id;
Expand Down

0 comments on commit 7cd5d7b

Please sign in to comment.