use of model.Rele in project aplicativo by InCasa.
the class ReleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rele);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
SharedPreferences mSharedPreferences = getSharedPreferences("ServerAdress", 0);
this.ip = mSharedPreferences.getString("servidor", " ");
final String URLRELE1 = "http://" + ip + "/backend/releValor/1";
final String URLRELE2 = "http://" + ip + "/backend/releValor/2";
final String URLRELE3 = "http://" + ip + "/backend/releValor/3";
final String URLRELE4 = "http://" + ip + "/backend/releValor/4";
final String URLPOSTRELE = "http://" + ip + "/backend/releValor";
Rele Objrele1 = new Rele();
Rele Objrele2 = new Rele();
Rele Objrele3 = new Rele();
Rele Objrele4 = new Rele();
Objrele1 = HomeActivity.Rele1;
Objrele2 = HomeActivity.Rele2;
Objrele3 = HomeActivity.Rele3;
Objrele4 = HomeActivity.Rele4;
getRele1(URLRELE1);
getRele2(URLRELE2);
getRele3(URLRELE3);
getRele4(URLRELE4);
Switch rele1 = (Switch) findViewById(R.id.switch1);
Switch rele2 = (Switch) findViewById(R.id.switch2);
Switch rele3 = (Switch) findViewById(R.id.switch3);
Switch rele4 = (Switch) findViewById(R.id.switch4);
TextView nomeRele1 = (TextView) findViewById(R.id.lblRele1);
TextView nomeRele2 = (TextView) findViewById(R.id.lblRele2);
TextView nomeRele3 = (TextView) findViewById(R.id.lblRele3);
TextView nomeRele4 = (TextView) findViewById(R.id.lblRele4);
nomeRele1.setText(Objrele1.getNome());
nomeRele2.setText(Objrele2.getNome());
nomeRele3.setText(Objrele3.getNome());
nomeRele4.setText(Objrele4.getNome());
rele1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (estado1 == isChecked) {
} else {
if (isChecked) {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", true);
jsonBody.put("idRele", 1);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
} else {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", false);
jsonBody.put("idRele", 1);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
}
}
}
});
rele2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (estado2 == isChecked) {
} else {
if (isChecked) {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", true);
jsonBody.put("idRele", 2);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
} else {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", false);
jsonBody.put("idRele", 2);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
}
}
}
});
rele3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (estado3 == isChecked) {
} else {
if (isChecked) {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", true);
jsonBody.put("idRele", 3);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
} else {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", false);
jsonBody.put("idRele", 3);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
}
}
}
});
rele4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (estado4 == isChecked) {
} else {
if (isChecked) {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", true);
jsonBody.put("idRele", 4);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
} else {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("valor", false);
jsonBody.put("idRele", 4);
} catch (JSONException e) {
e.printStackTrace();
}
postRele(jsonBody, URLPOSTRELE);
}
}
}
});
}
Aggregations