Page MenuHomec4science

PatientGUI.java
No OneTemporary

File Metadata

Created
Thu, Jan 2, 22:39

PatientGUI.java

This document is not UTF8. It was detected as ISO-8859-1 (Latin 1) and converted to UTF8 for display.
package com.example.genomicprivacy;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import FrameWork.Patient;
import FrameWork.RequestPatient;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class PatientGUI extends Activity {
/**
* List View for all the requests
*/
private ListView listView;
/**
* The patient who has logged
*/
private Patient p;
/**
* ID of the patient
*/
private int id;
/**
* Number of request refused
*/
private int sizeRefused = 0;
/**
* Number of request pending
*/
private int sizeAwait = 0;
/**
* Number of request accepted
*/
private int sizeAccept = 0;
/**
* Number of request accepted and tested
*/
private int sizeAcceptTest = 0;
/**
* List of the request refused that we show to the user
*/
private ArrayList<String> refusedRequestString = new ArrayList<String>();
/**
* List of the request pending that we show to the user
*/
private ArrayList<String> awaitingRequestString = new ArrayList<String>();
/**
* List of the request accepted that we show to the user
*/
private ArrayList<String> acceptedRequestString = new ArrayList<String>();
/**
* List of the request accepted and tested
*/
private ArrayList<String> acceptedTestedRequestString = new ArrayList<String>();
/**
* List of all the request that we use for computation
*/
private ArrayList<RequestPatient> allRequest = new ArrayList<RequestPatient>();
/**
* List of the requests refused that we use for computation
*/
private ArrayList<RequestPatient> refusedRequest = new ArrayList<RequestPatient>();
/**
* List of the requests pending that we use for computation
*/
private ArrayList<RequestPatient> awaitRequest = new ArrayList<RequestPatient>();
/**
* List of the requests accepted that we use for computation
*/
private ArrayList<RequestPatient> acceptedRequest = new ArrayList<RequestPatient>();
/**
* List of the requests accepted and test
*/
private ArrayList<RequestPatient> acceptedTestedRequest = new ArrayList<RequestPatient>();
@Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
id = intent.getIntExtra("id", 0);
p = new Patient(id, null, ContextApp.getP().getJsrSPU(), ContextApp
.getP().getJswSPU(), null, null, null, null);
super.onCreate(savedInstanceState);
setContentView(R.layout.patient);
new GetRequest().execute();
listView = (ListView) findViewById(R.id.listViewRequest);
// register onClickListener to handle click events on each item
listView.setOnItemClickListener(new OnItemClickListener() {
// argument position gives the index of item which is clicked
public void onItemClick(AdapterView<?> arg0, View v, int position,
long arg3) {
Intent i = new Intent(ContextApp.getContext(), RequestGUI.class);
ContextApp.setRp(allRequest.get(position));
startActivity(i);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.patient, menu);
allRequest.clear();
refusedRequestString.clear();
awaitingRequestString.clear();
acceptedRequestString.clear();
acceptedRequest.clear();
awaitRequest.clear();
refusedRequest.clear();
new GetRequest().execute();
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Reset all values for the refresh
allRequest.clear();
refusedRequestString.clear();
awaitingRequestString.clear();
acceptedRequestString.clear();
acceptedRequest.clear();
awaitRequest.clear();
refusedRequest.clear();
// Handle item selection
switch (item.getItemId()) {
case R.id.refresh_settings:
new GetRequest().execute();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onResume() {
super.onResume();
allRequest.clear();
refusedRequestString.clear();
awaitingRequestString.clear();
acceptedRequestString.clear();
acceptedRequest.clear();
awaitRequest.clear();
refusedRequest.clear();
new GetRequest().execute();
}
/**
* Asynchronous task for getting all the requests from the server. Sort them
* by their flag.
*
* @author Serrano Kevin
* @author Weber Jeremy
*/
public class GetRequest extends AsyncTask<Void, Void, ArrayList<String>> {
@Override
protected ArrayList<String> doInBackground(Void... params) {
allRequest.clear();
refusedRequestString.clear();
awaitingRequestString.clear();
acceptedRequestString.clear();
acceptedRequest.clear();
awaitRequest.clear();
refusedRequest.clear();
allRequest = p.checkNewRequest();
for (int i = 0; i < allRequest.size(); i++) {
RequestPatient rp = null;
switch (allRequest.get(i).getFlag()) {
case 0: // waiting
rp = allRequest.get(i);
awaitingRequestString.add(" • " + rp.getNameTest()
+ "\n Waiting");
awaitRequest.add(allRequest.get(i));
break;
case 1: // accepted
rp = allRequest.get(i);
acceptedRequestString.add(" • " + rp.getNameTest()
+ "\n Accepted");
acceptedRequest.add(allRequest.get(i));
break;
case 2:// refused
rp = allRequest.get(i);
refusedRequestString.add(" • " + rp.getNameTest()
+ "\n Refused");
refusedRequest.add(allRequest.get(i));
break;
case 3: // accepted and tested
rp = allRequest.get(i);
acceptedTestedRequestString.add(" • "
+ rp.getNameTest() + "\n Tested");
acceptedTestedRequest.add(allRequest.get(i));
}
}
sizeAccept = acceptedRequestString.size();
sizeRefused = refusedRequestString.size();
sizeAwait = awaitingRequestString.size();
sizeAcceptTest = acceptedTestedRequestString.size();
// Append the three list together & re create the ArrayList<Request> allRequest
// in the correct order
allRequest.clear();
for (int i = 0; i < sizeAwait; i++) {
allRequest.add(awaitRequest.get(i));
}
for (int j = 0; j < sizeAccept; j++) {
awaitingRequestString.add(acceptedRequestString.get(j));
allRequest.add(acceptedRequest.get(j));
}
for (int j = 0; j < sizeRefused; j++) {
awaitingRequestString.add(refusedRequestString.get(j));
allRequest.add(refusedRequest.get(j));
}
for (int i = 0; i < sizeAcceptTest; i++) {
awaitingRequestString.add(acceptedTestedRequestString.get(i));
allRequest.add(acceptedTestedRequest.get(i));
}
return awaitingRequestString;
}
@Override
protected void onPostExecute(ArrayList<String> result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
// Get ListView object from xml
listView.setAdapter(new ArrayAdapter<String>(ContextApp
.getContext(), R.layout.listitem, result));
listView.setDivider(new ColorDrawable(Color.BLACK));
listView.setDividerHeight(10);
}
}
}

Event Timeline