Skip to content

Commit

Permalink
Merge pull request #12 from cmsc436/read-prescription
Browse files Browse the repository at this point in the history
Read prescription
  • Loading branch information
0queue authored May 2, 2017
2 parents f4a9872 + 0e0a2f1 commit 23ed951
Show file tree
Hide file tree
Showing 16 changed files with 433 additions and 116 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ Please place APKs of your test apps in [this folder](https://drive.google.com/dr

One row per patient, with columns:

Patient ID | Date Assigned | Frequency | Column per Test App ... | Status
--- | --- | --- | --- | ---
String | Google Sheets Datetime | Jenkins format (eventually) | Difficulty Integer (0 is disable, 1 is easiest) | Assigned, Ignored, or Completed
Patient ID | Date Assigned | Frequency | Number of trials per app | Column per Test App ... | Status
--- | --- | --- | --- | --- | ---
String | DD/MM/YYYY HH:MM:SS (24 hour time) | Integer > 0 | Jenkins format (eventually) | Difficulty Integer (0 is disable, 1 is easiest) | Assigned, Ignored, or Completed
17 changes: 7 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.umd.cmsc436.mstestsuite">
package="edu.umd.cmsc436.mstestsuite">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_testsuite"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme.ColorBlind">
<activity android:name=".IntroActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<service
android:name=".model.PharmacistService"
android:enabled="true"
android:exported="false"></service>

<activity android:name=".MainActivity"></activity>
<activity android:name=".MainActivity"/>
</application>

</manifest>
126 changes: 123 additions & 3 deletions app/src/main/java/edu/umd/cmsc436/mstestsuite/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
package edu.umd.cmsc436.mstestsuite;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDialog;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.Arrays;
import java.util.Comparator;

import edu.umd.cmsc436.mstestsuite.data.ActionsAdapter;
import edu.umd.cmsc436.mstestsuite.model.UserManager;
import edu.umd.cmsc436.sheets.Sheets;

public class MainActivity extends AppCompatActivity implements MainContract.View {
public class MainActivity extends AppCompatActivity implements MainContract.View, Sheets.Host {

private RecyclerView mRecyclerView;
private GridLayoutManager mLayoutManager;
Expand All @@ -40,6 +53,11 @@ public class MainActivity extends AppCompatActivity implements MainContract.View

private MainContract.Presenter mPresenter;

private static final int REQUEST_CODE_INSTALL = 1001;
private static final int REQUEST_EXTERNAL_PERMISSION = 1002;

private File mInstallCache;

@SuppressLint("ShowToast")
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -48,6 +66,8 @@ protected void onCreate(Bundle savedInstanceState) {

setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

mInstallCache = null;

mPeekButton = (Button) findViewById(R.id.peeked_begin_button);
mPeekButton.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -246,6 +266,7 @@ public void showHistoryDialog(final String user) {
final Dialog dialog = new AppCompatDialog(this);
final String [] app_array = getResources().getStringArray(R.array.display_names);

@SuppressLint("InflateParams")
View root = dialog.getLayoutInflater().inflate(R.layout.history_chooser, null, false);

ListView lv = (ListView) root.findViewById(R.id.app_history_listview);
Expand All @@ -271,10 +292,109 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
dialog.show();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mPresenter.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_INSTALL) {
mPresenter.onPackageInstalled();
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
mPresenter.onRequestPermissionsResult(requestCode, permissions, grantResults);

if (requestCode == REQUEST_EXTERNAL_PERMISSION && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (mInstallCache != null) {
try {
installPackage(mInstallCache);
} catch (IOException e) {
Log.e(getClass().getCanonicalName(), "install failed for " + mInstallCache.getAbsolutePath());
}
}
}
}

@Override
public Sheets.Host getHost() {
return this;
}

@Override
public Activity getActivity() {
return this;
}

@SuppressWarnings("ResultOfMethodCallIgnored")
@Override
public void installPackage(File f) throws IOException {

FileChannel inChannel = new FileInputStream(f).getChannel();
File downloadsFolder = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);

if (downloadsFolder == null) {
throw new FileNotFoundException("downloads folder");
}

File outFile = new File(downloadsFolder, f.getName());
outFile.setReadable(true);
outFile.setWritable(true);
FileChannel outChannel = new FileOutputStream(outFile).getChannel();


if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
mInstallCache = f;
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_EXTERNAL_PERMISSION);
return;
}


try {
inChannel.transferTo(0, inChannel.size(), outChannel);
} finally {
if (inChannel != null) {
inChannel.close();
}

outChannel.close();
}

Intent i = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.parse("file://" + outFile.getAbsolutePath()), "application/vnd.android.package-archive");
startActivityForResult(i, REQUEST_CODE_INSTALL);
}

@Override
public void onBackPressed() {
if (mPresenter.onBackPressed()) {
super.onBackPressed();
}
}

@Override
public int getRequestCode(Sheets.Action action) {
switch (action) {
case REQUEST_ACCOUNT_NAME:
return 436;
case REQUEST_AUTHORIZATION:
return 437;
case REQUEST_CONNECTION_RESOLUTION:
return 438;
case REQUEST_PERMISSIONS:
return 439;
case REQUEST_PLAY_SERVICES:
return 440;
default:
return 435;
}
}

@Override
public void notifyFinished(Exception e) {
if (e != null) {
Log.e(getClass().getCanonicalName(), e.toString());
}
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/edu/umd/cmsc436/mstestsuite/MainContract.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package edu.umd.cmsc436.mstestsuite;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;

import java.io.File;
import java.io.IOException;

import edu.umd.cmsc436.mstestsuite.data.ActionsAdapter;
import edu.umd.cmsc436.mstestsuite.model.UserManager;
import edu.umd.cmsc436.sheets.Sheets;

/**
* Define which part of the app can do what
Expand All @@ -22,6 +29,9 @@ interface View {
void startPracticeMode(String packageName) throws ActivityNotFoundException;
Context getContext ();
void showUserSwitcher (String[] users);
Sheets.Host getHost ();
Activity getActivity ();
void installPackage (File f) throws IOException;
void showHistoryDialog (String user);
}

Expand All @@ -35,5 +45,8 @@ interface Presenter {
void onDestroy ();
void onUserSelected (String patient_id);
void onUserCreated (String patient_id, UserManager.Handedness h, String dateOfBirth, UserManager.Gender gender);
void onActivityResult(int requestCode, int resultCode, Intent data);
void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults);
void onPackageInstalled ();
}
}
Loading

0 comments on commit 23ed951

Please sign in to comment.