use of Model.User in project aplicativo by InCasa.
the class ReleActivity method getRele2.
public void getRele2(String URLRELE2) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLRELE2, null, new Response.Listener<JSONObject>() {
//Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
String temp = "";
try {
Switch rele2 = (Switch) findViewById(R.id.switch2);
temp = response.getString("valor");
if (temp.equals("0")) {
rele2.setChecked(false);
estado2 = false;
} else {
rele2.setChecked(true);
estado2 = true;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
//Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
Context context = getApplicationContext();
CharSequence text = "Erro na requisição";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
//fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
//Adiciona a requisição á fila de requisições
fila.add(req);
}
use of Model.User in project aplicativo by InCasa.
the class LoginActivity method Login.
public void Login(String URLLOGIN) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, URLLOGIN, null, new Response.Listener<JSONObject>() {
//Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
boolean Authorization = false;
try {
Authorization = response.getBoolean("Authorized");
} catch (JSONException e) {
e.printStackTrace();
}
if (Authorization == true) {
//Obtem a instancia vazia do User
User user = User.getInstancia();
//Adiciona login e senha na instancia
user.setLogin(login);
user.setSenha(senha);
Intent it = new Intent(LoginActivity.this, HomeActivity.class);
startActivity(it);
finish();
}
}
}, new Response.ErrorListener() {
//Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
Context context = getApplicationContext();
CharSequence text = "Login ou Senha incorretos";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
String auth = new String(Base64.encode((login + ":" + senha).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
//fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
//Adiciona a requisição á fila de requisições
fila.add(req);
}
use of Model.User in project aplicativo by InCasa.
the class HomeActivity method getArduino.
public void getArduino(String URLGETARDUINO) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETARDUINO, null, new Response.Listener<JSONObject>() {
//Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
Arduino arduino = Arduino.getInstancia();
//adiciona as informações no objeto arduino
try {
arduino.setIdArduino(response.getInt("id"));
arduino.setIp(response.getString("ip"));
arduino.setMac(response.getString("mac"));
arduino.setMask(response.getString("mask"));
arduino.setGateway(response.getString("gateway"));
arduino.setPorta(response.getString("porta"));
arduino.setPinoRele1(response.getString("PinoRele1"));
arduino.setPinoRele2(response.getString("PinoRele2"));
arduino.setPinoRele3(response.getString("PinoRele3"));
arduino.setPinoRele4(response.getString("PinoRele4"));
arduino.setPinoDHT22(response.getString("PinoDHT"));
arduino.setPinoLDR(response.getString("PinoLDR"));
arduino.setPinoPresenca(response.getString("PinoPresenca"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
//Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
//fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
//Adiciona a requisição á fila de requisições
fila.add(req);
}
use of Model.User in project aplicativo by InCasa.
the class HomeActivity method getSensorTemperatura.
public void getSensorTemperatura(String URLGETTEMPERATURA) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETTEMPERATURA, null, new Response.Listener<JSONObject>() {
//Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
try {
Temperatura temp = Temperatura.getInstancia();
temp.setIdTemperatura(response.getInt("id"));
temp.setNome(response.getString("nome"));
temp.setDescricao(response.getString("descricao"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
//Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
//fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
//Adiciona a requisição á fila de requisições
fila.add(req);
}
use of Model.User in project aplicativo by InCasa.
the class HomeActivity method getRele1.
public void getRele1(String URLGETRELE1) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETRELE1, null, new Response.Listener<JSONObject>() {
//Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
try {
Rele1.setIdRele(response.getInt("id"));
Rele1.setNome(response.getString("nome"));
Rele1.setDescricao(response.getString("descricao"));
Rele1.setPorta(response.getInt("porta"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
//Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
//fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
//Adiciona a requisição á fila de requisições
fila.add(req);
}
Aggregations