Page MenuHomec4science

RequestGUI.java
No OneTemporary

File Metadata

Created
Thu, Jan 2, 21:24

RequestGUI.java

package com.example.genomicprivacy;
import java.util.ArrayList;
import FrameWork.ClinicalFactorsTable;
import android.app.Activity;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
/**
* @author Serrano Kevin
* @author Weber Jeremy
*
*/
public class RequestGUI extends Activity {
/**
* Info about the request
*/
TextView tv;
/**
* Button that send the consent/refusal for the request
*/
Button send;
/**
* Check box for accepting the conditions
*/
CheckBox acceptCond;
/**
* Button for accepting the request
*/
RadioButton acceptButton;
/**
* Button for refuse the request
*/
RadioButton refuseButton;
/**
* CheckBox for every clinical factors
*/
CheckBox checkBoxCF;
/**
* Layout for the clinical factors' check Box
*/
LinearLayout linearCheckboxView;
/**
* Text View for access the consent
*/
TextView consent;
ClinicalFactorsTable cft;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_request_gui);
tv = (TextView) findViewById(R.id.info);
send = (Button) findViewById(R.id.send_consent);
acceptButton = (RadioButton) findViewById(R.id.Accept);
refuseButton = (RadioButton) findViewById(R.id.Refuse);
acceptCond = (CheckBox) findViewById(R.id.acceptConsent);
linearCheckboxView = (LinearLayout) findViewById(R.id.linearCheckBoxes);
consent = (TextView) findViewById(R.id.consent);
tv.setText("Request selected is : " + ContextApp.getRp().getId_r());
if(ContextApp.getRp().getId_t() == 12){
Toast toast = Toast.makeText(ContextApp.getContext(),
"Please wait, the clinical factors are loading", 8000);
toast.show();
}
consent.setClickable(true);
consent.setMovementMethod(LinkMovementMethod.getInstance());
String accessConsent = "<a href='http://128.178.151.209:8080/Consent/Consent.html'> Consent </a>";
consent.setText(Html.fromHtml(accessConsent));
// Disable the checkBox and RadioGroup for the request whose are already
// accepted or refused
if (ContextApp.getRp().getFlag() != 0) {
acceptCond.setEnabled(false);
acceptButton.setEnabled(false);
refuseButton.setEnabled(false);
send.setEnabled(false);
}
// When we click on the accept button we have to set the other one to
// false and inversely
acceptButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
acceptButton.setChecked(true);
refuseButton.setChecked(false);
}
});
refuseButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
acceptButton.setChecked(false);
refuseButton.setChecked(true);
}
});
new getCF().execute();
send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (ContextApp.getRp().getFlag() != 0) {
acceptCond.setEnabled(false);
acceptButton.setEnabled(false);
refuseButton.setEnabled(false);
send.setEnabled(false);
} else {
if (!acceptButton.isChecked() && !refuseButton.isChecked()) {
// nothing selected
Toast toast = Toast.makeText(ContextApp.getContext(),
"Nothing was selected", 6000);
toast.show();
} else if (acceptButton.isChecked()) {
if (acceptCond.isChecked()) {
// Send the consent
new SendConsent().execute(true);
Toast toast = Toast.makeText(
ContextApp.getContext(),
"Your consent was sent successfully", 6000);
toast.show();
// Disable the checkBox and RadioGroup for the
// request whose are already
// accepted or refused
} else {
// Do nothing but tell the user that he have to
// check
// the box
Toast toast = Toast.makeText(
ContextApp.getContext(),
"Sorry you have to accept the aggreement",
4000);
toast.show();
}
} else if (refuseButton.isChecked()) {
// Send back the refuse
new SendConsent().execute(false);
Toast toast = Toast.makeText(ContextApp.getContext(),
"Your refusal was sent successfully", 6000);
toast.show();
// Disable the checkBox and RadioGroup for the request
// whose are already
// accepted or refused
if (ContextApp.getRp().getFlag() != 0) {
acceptCond.setEnabled(false);
acceptButton.setEnabled(false);
refuseButton.setEnabled(false);
send.setEnabled(false);
}
}
}
}
});
}
/**
* Asynchronous task for sending the consent of the patient to the server
*
* @author Serrano Kevin
* @author Weber Jeremy
*
*/
public class SendConsent extends AsyncTask<Boolean, Void, Void> {
@Override
protected Void doInBackground(Boolean... consent) {
ArrayList[] cf = new ArrayList[2];
ArrayList<Boolean> valeur = new ArrayList<Boolean>();
for (int i = 0; i < linearCheckboxView.getChildCount(); i++) {
CheckBox check = (CheckBox) linearCheckboxView.getChildAt(i);
valeur.add(check.isChecked());
}
cf[0] = cft.getIdCF();
cf[1] = valeur;
// The consent is accepted and we have to update the CFs
ArrayList[] upCF = ContextApp.getP().updateCF(cf);
ContextApp.getP().sendConsent(ContextApp.getRp(), consent[0], upCF);
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
for (int i = 0; i < linearCheckboxView.getChildCount(); i++) {
linearCheckboxView.getChildAt(i).setEnabled(false);
}
acceptCond.setEnabled(false);
acceptButton.setEnabled(false);
refuseButton.setEnabled(false);
send.setEnabled(false);
}
}
/**
* Asynchronous task for retrieve and decrypt the clinical factors
*
* @author Serrano Kevin
* @author Weber Jeremy
*
*/
public class getCF extends AsyncTask<Void, Void, ClinicalFactorsTable> {
@Override
protected ClinicalFactorsTable doInBackground(Void... params) {
// TODO Auto-generated method stub
cft = ContextApp.getP().checkClinicalFactors(ContextApp.getRp());
cft = ContextApp.getP().fullfillClinicalFactors(cft);
return cft;
}
@Override
protected void onPostExecute(ClinicalFactorsTable result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
for (int i = 0; i < result.getClinicalFactors().length; i++) {
checkBoxCF = new CheckBox(ContextApp.getContext());
checkBoxCF.setText(result.getClinicalFactors()[i]);
checkBoxCF.setTextColor(Color.BLACK);
checkBoxCF.setChecked(result.getCFchecked()[i]);
if (ContextApp.getRp().getFlag() != 0) {
checkBoxCF.setEnabled(false);
}
linearCheckboxView.addView(checkBoxCF);
}
}
}
}

Event Timeline