Skip to content

Commit

Permalink
Merge pull request #5 from cmsc436/integration-library
Browse files Browse the repository at this point in the history
First addition of a helper library to interact with third party apps
  • Loading branch information
MichelleCody authored Apr 25, 2017
2 parents 8cf222b + 3b25b20 commit 941ad0c
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 7 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,40 @@ Front end for the various MS test apps.

## How to integrate a test app

There are three intent actions that should be caught:
- `<your package name>.action.TRIAL`
- `<your package name>.action.PRACTICE`
- `<your package name>.action.HELP`

For example, if MS Test Suite reacted to Practice Mode, it would catch intents with the `edu.umd.cmsc436.mstestsuite.action.PRACTICE` action. This way, a specific test and mode can be simulateously specified.

`.PRACTICE` and `.HELP` don't have any arguments or expect any results.

`.TRIAL` has 4 arguments:
- Appendage, which is a `Sheets.TestType` (from the [sheets436](https://github.com/cmsc436/sheets436) library)
- Trial Num, an integer, the current trial out of this appendage's number of trials, for display purposes
- Trial Out Of, an integer, the current appendage's number of trials, for display purposes
- Patient ID, a string, for storing raw data appropriately

`.TRIAL` also expects a single float result, the score for the trial. This can be done with the [`Activity#setResult(int, Intent)`](https://developer.android.com/reference/android/app/Activity.html#setResult(int, android.content.Intent)) method, and the intent from the `TrialMode.getResultIntent(float)` helper static method.

There are a few static methods to help with argument extraction as well:
- `getAppendage(Intent)`
- `getTrialNum(Intent)`
- `getTrialOutOf(Intent)`
- `getPatientId(Intent)`

These will help with getting info out of intents delivered with the `.TRIAL` action.

The helper library uses types from the sheets436 library, so make sure to include that as a dependency. There are also a few color resources defined to help with consistency:
- `colorPrimary436`, orange
- `colorPrimaryDark436`, a slightly darker orange (for the status bar, if present)
- `colorAccent436`, blue
- `colorAccentLight436`, a light blue
- `colorBackground436`, a light gray

These value were taken from [colorcombos.com](http://www.colorcombos.com/color-schemes/89/ColorCombo89.html).

## Prescription Format

One row per patient, with columns:
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'

compile 'com.android.support:design:25.3.1'
compile project(':frontendhelper')
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme.ColorBlind">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.ColorBlind" parent="AppTheme">
<item name="colorPrimary">@color/colorPrimary436</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark436</item>
<item name="colorAccent">@color/colorAccent436</item>
</style>

<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@android:color/white</item>
</style>

<style name="SquareLayoutTheme" parent="ThemeOverlay.AppCompat.Light">
<style name="SquareLayoutTheme" parent="AppTheme.ColorBlind">
<item name="android:background">@drawable/ripple</item>
<item name="android:color">@android:color/white</item>
<item name="colorControlHighlight">@color/colorAccent</item>
<item name="colorControlHighlight">?attr/colorAccent</item>
</style>

<style name="DailyButtonTheme" parent="Widget.AppCompat.Button.Colored">
<item name="android:textSize">22sp</item>
<item name="android:textColor">@android:color/black</item>
<item name="android:textColor">@android:color/white</item>
<item name="android:textAlignment">center</item>
<item name="android:drawableRight">@drawable/ic_arrow_forward_black_24dp</item>
</style>
Expand Down
1 change: 1 addition & 0 deletions frontendhelper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
41 changes: 41 additions & 0 deletions frontendhelper/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
minSdkVersion 22
targetSdkVersion 25
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services-auth:10.2.1'
compile('com.google.api-client:google-api-client-android:1.22.0') {
exclude group: 'org.apache.httpcomponents'
exclude group: 'com.google.code.findbugs'
}
compile('com.google.apis:google-api-services-sheets:v4-rev466-1.22.0') {
exclude group: 'org.apache.httpcomponents'
exclude group: 'com.google.code.findbugs'
}
compile project(':sheets436')
}
25 changes: 25 additions & 0 deletions frontendhelper/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/thomas/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# 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
11 changes: 11 additions & 0 deletions frontendhelper/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.umd.cmsc436.frontendhelper">

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package edu.umd.cmsc436.frontendhelper;

import android.content.Intent;
import android.support.annotation.Nullable;

import edu.umd.cmsc436.sheets.Sheets;

/**
* Helper functions to get arguments from TRIAL actions
*/

public class TrialMode {

public static final String KEY_APPENDAGE = "appendage";
public static final String KEY_TRIAL_NUM = "trial num";
public static final String KEY_TRIAL_OUT_OF = "trial out of";
public static final String KEY_PATIENT_ID = "patient id";
public static final String KEY_SCORE = "score";

/**
* Extract the Test Type from the intent
*
* Reuses the Sheets lib type for convenience
* @param i the Intent from the front end, with the .TRIAL action
* @return Null if the argument isn't found, TestType otherwise
*/
@Nullable
public static Sheets.TestType getAppendage (Intent i) {
int temp = i.getIntExtra(KEY_APPENDAGE, -1);

if (temp < 0 || temp >= Sheets.TestType.values().length) {
return null;
}

return Sheets.TestType.values()[temp];
}

/**
* Get the current trial number from the frontend intent
*
* For display purposes
* @param i intent from frontend, with .TRIAL action
* @return the current trial, or -1 if no arg found
*/
public static int getTrialNum (Intent i) {
return i.getIntExtra(KEY_TRIAL_NUM, -1);
}

/**
* Get the total number of trials from the frontend intent
*
* For display purposes
* @param i intent from frontend, with .TRIAL action
* @return the total number of trials, or -1 if no arg found
*/
public static int getTrialOutOf (Intent i) {
return i.getIntExtra(KEY_TRIAL_OUT_OF, -1);
}

/**
* Get the patient id for the current trial from the frontend intent
*
* To be used to store raw data for the patient
* @param i intent from the frontend, with .TRIAL action
* @return the patient id, or null if not found
*/
@Nullable
public static String getPatientId (Intent i) {
return i.getStringExtra(KEY_PATIENT_ID);
}

/**
* Create a new intent to return a score result
* @param score the score for the current single trial
* @return an intent to be used with {@link android.app.Activity#setResult(int, Intent)}
*/
public static Intent getResultIntent (float score) {
Intent i = new Intent();
i.getExtras().putFloat(KEY_SCORE, score);

return i;
}
}
8 changes: 8 additions & 0 deletions frontendhelper/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary436">#FF9933</color>
<color name="colorPrimaryDark436">#ff7700</color>
<color name="colorAccent436">#003399</color>
<color name="colorAccentLight436">#99CCCC</color>
<color name="colorBackground436">#CCCCCC</color>
</resources>
3 changes: 3 additions & 0 deletions frontendhelper/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">frontendhelper</string>
</resources>
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app'
include ':app', ':frontendhelper', ':sheets436'
2 changes: 2 additions & 0 deletions sheets436/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
configurations.maybeCreate("default")
artifacts.add("default", file('sheets436-0.0.5-release.aar'))
Binary file added sheets436/sheets436-0.0.5-release.aar
Binary file not shown.

0 comments on commit 941ad0c

Please sign in to comment.