importandroid.app.*;importandroid.content.*;importandroid.os.*;importandroid.util.*;importandroid.view.*;importandroid.widget.*;importjava.util.*;importorg.apache.http.*;importorg.apache.http.message.*;importorg.json.*;publicclassverextendsActivity{TextViewtvnome;TextViewtvgenero;TextViewtvautonomia;TextViewtvmedicamentos;TextViewtxtCreatedAt;CheckBoxchkfemenino;CheckBoxchkmasculino;CheckBoxchkautonomo;CheckBoxchkdependente;CheckBoxchkacamado;CheckBoxchktipo1;CheckBoxchktipo2;CheckBoxchkparkinson;CheckBoxchkalzeimer;CheckBoxchkcoracao;CheckBoxchkavc;CheckBoxchkoutra;TextViewtvoutra;ButtonbtnEditar;ButtonbtnVoltar;Stringpid;Stringid;//ProgressDialogprivateProgressDialogpDialog;//JSONparserclassJSONParserjsonParser=newJSONParser();//singleproducturlprivatestaticfinalStringurl_idoso_detalhes="http://robilaks.byethost11.com/psi/htdocs/get_product_details.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_IDOSO = "product";
private static final String TAG_PID = "pid";
private static final String TAG_NOME = "nome";
private static final String TAG_GENERO = "genero";
private static final String TAG_AUTONOMIA = "autonomia";
private static final String TAG_DIABETES = "diabetes";
private static final String TAG_PARKINSON = "parkinson";
private static final String TAG_ALZEIMER = "alzeimer";
private static final String TAG_AVC = "avc";
private static final String TAG_OUTRAO = "outrao";
private static final String TAG_OUTRA = "outra";
private static final String TAG_MEDICAMENTOS = "medicamentos";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ver);
new GetProductDetails().execute();
// save button
btnEditar = (Button) findViewById(R.id.btnEditar);
btnVoltar = (Button) findViewById(R.id.btnVoltar);
// getting product details from intent
Intent i = getIntent();
tvnome = (TextView) findViewById(R.id.tvnome);
tvmedicamentos = (TextView) findViewById(R.id.tvmedicamentos);
chkfemenino = (CheckBox) findViewById(R.id.chkfemenino);
chkmasculino = (CheckBox) findViewById(R.id.chkmasculino);
chkautonomo = (CheckBox) findViewById(R.id.chkautonomo);
chkdependente = (CheckBox) findViewById(R.id.chkdependente);
chkacamado = (CheckBox) findViewById(R.id.chkacamado);
chktipo1 = (CheckBox) findViewById(R.id.chktipo1);
chktipo2 = (CheckBox) findViewById(R.id.chktipo2);
chkparkinson = (CheckBox) findViewById(R.id.chkparkinson);
chkalzeimer = (CheckBox) findViewById(R.id.chkalzeimer);
chkcoracao = (CheckBox) findViewById(R.id.chkcoracao);
chkavc = (CheckBox) findViewById(R.id.chkavc);
chkoutra = (CheckBox) findViewById(R.id.chkoutra);
tvoutra = (TextView) findViewById(R.id.tvoutra);
// getting product id (pid) from intent
pid = i.getStringExtra(TAG_PID);
id = i.getStringExtra(TAG_PID);
//new GetProductDetails().execute();
// save button click event
btnEditar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Launching create new product activity
Intent i = new Intent(getApplicationContext(), editar.class);
/* pDialog = new ProgressDialog(ver.this);
pDialog.setMessage("Um Momento...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();*/
i.putExtra(TAG_PID, id);
startActivity(i);
}
});
btnVoltar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Launching create new product activity
Intent i = new Intent(getApplicationContext(), consultas.class);
i.putExtra(TAG_PID, pid);
startActivity(i);
}
});
}
/**
* Background Async Task to Get complete product details
* */
class GetProductDetails extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(ver.this);
pDialog.setMessage("A carregar dados...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Getting product details in background thread
* */
protected String doInBackground(String... params) {
runOnUiThread(new Runnable() {
public void run() {
// Check for success tag
int success;
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("pid", pid));
// getting product details by making HTTP request
// Note that product details url will use GET request
JSONObject json = jsonParser.makeHttpRequest(
url_idoso_detalhes, "GET", params);
// check your log for json response
Log.d("Single Product Details", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully received product details
JSONArray productObj = json
.getJSONArray(TAG_IDOSO); // JSON Array
Log.d("Single Product Dssseeeetails", productObj.toString());
// get first product object from JSON Array
JSONObject product = productObj.getJSONObject(0);
int genero = Integer.valueOf(product.getString(TAG_GENERO));
int autonomia = Integer.valueOf(product.getString(TAG_AUTONOMIA));
int diabetes =Integer.valueOf(product.getString(TAG_DIABETES));
int parkinson =Integer.valueOf(product.getString(TAG_PARKINSON));
int alzeimer =Integer.valueOf(product.getString(TAG_ALZEIMER));
int avc =Integer.valueOf(product.getString(TAG_AVC));
int outrao =Integer.valueOf(product.getString(TAG_OUTRAO));
int generofem = 1;
int generomasc = 2;
int aautonomo = 1;
int adependente = 2;
int aacamado = 3;
int tipo1 = 1;
int tipo2 = 2;
int pparkinson = 1;
int palzeimer = 1;
int pavc = 1;
int poutrao = 1;
// display product data in EditText
if(genero == generofem){
chkfemenino.setEnabled(false);
chkmasculino.setEnabled(false);
chkfemenino.setChecked(true);
}
if(genero == generomasc){
chkmasculino.setEnabled(false);
chkfemenino.setEnabled(false);
chkmasculino.setChecked(true);
}
if(autonomia == aautonomo){
chkautonomo.setEnabled(false);
chkdependente.setEnabled(false);
chkacamado.setEnabled(false);
chkautonomo.setChecked(true);
}
if(autonomia == adependente){
chkdependente.setEnabled(false);
chkautonomo.setEnabled(false);
chkacamado.setEnabled(false);
chkdependente.setChecked(true);
}
if(autonomia == aacamado){
chkacamado.setEnabled(false);
chkdependente.setEnabled(false);
chkautonomo.setEnabled(false);
chkacamado.setChecked(true);
}
if(diabetes == tipo1){
chktipo1.setEnabled(false);
chktipo1.setChecked(true);
}
if(diabetes == tipo2){
chktipo2.setEnabled(false);
chktipo2.setChecked(true);
}
if(parkinson == pparkinson){
chkparkinson.setEnabled(false);
chkparkinson.setChecked(true);
}
if(alzeimer == palzeimer){
chkalzeimer.setEnabled(false);
chkalzeimer.setChecked(true);
}
if(avc == pavc){
chkavc.setEnabled(false);
chkavc.setChecked(true);
}
if(outrao == poutrao){
chkoutra.setEnabled(false);
chkoutra.setChecked(true);
tvoutra.setText(product.getString(TAG_OUTRA));
}
tvnome.setText(product.getString(TAG_NOME));
tvmedicamentos.setText(product.getString(TAG_MEDICAMENTOS));
}else{
// product with pid not found
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once got all details
pDialog.dismiss();
}
}
}