use of com.android.volley.RequestQueue in project aplicativo by InCasa.
the class ReleActivity method postRele.
public void postRele(JSONObject json, String URLPOSTRELE) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, URLPOSTRELE, json, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Context context = getApplicationContext();
CharSequence text = "Erro no cadastro";
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 com.android.volley.RequestQueue in project aplicativo by InCasa.
the class ServerActivity method testeServer.
public void testeServer(final String ipServer) {
final ProgressBar bar = (ProgressBar) findViewById(R.id.progressBar);
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, "http://" + ipServer + "/backend/teste", null, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
bar.setProgress(60);
Context context = getApplicationContext();
CharSequence text = "Servidor: OK";
int duration = Toast.LENGTH_SHORT;
saveServer(ipServer);
bar.setProgress(80);
Toast toast = Toast.makeText(context, text, duration);
toast.show();
bar.setProgress(100);
Intent it = new Intent(ServerActivity.this, LoginActivity.class);
startActivity(it);
}
}, new Response.ErrorListener() {
// Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
Context context = getApplicationContext();
CharSequence text = "Erro no servidor";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
bar.setProgress(0);
}
});
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.RequestQueue in project aplicativo by InCasa.
the class FragmentArduino method GetConfig.
public void GetConfig(String URLGET) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGET, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// obtem a instancia do arduino
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() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Arduino: Erro!", Toast.LENGTH_SHORT).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;
}
};
// Add the request to the RequestQueue.
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(getActivity().getApplicationContext());
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.RequestQueue in project aplicativo by InCasa.
the class FragmentArduino method SaveConfig.
public void SaveConfig(JSONObject json, String URLCADASTRO) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, URLCADASTRO, json, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(getActivity(), "Configuração Arduino: Configuração salva com Sucesso !", Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Arduino: Erro ao salvar a configuração !", Toast.LENGTH_SHORT).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;
}
};
// Add the request to the RequestQueue.
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(getActivity().getApplicationContext());
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.RequestQueue in project aplicativo by InCasa.
the class FragmentSensor method UpdateLuminosidade.
public void UpdateLuminosidade(JSONObject json, String URLUPDATE) {
URLUPDATE = URLUPDATE + lumi.getIdLuminosidade();
JsonObjectRequest req = new JsonObjectRequest(Request.Method.PUT, URLUPDATE, json, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(getActivity(), "Configuração Luminosidade: Atualizado com sucesso !", Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Luminosidade: Erro na atualização !", Toast.LENGTH_SHORT).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;
}
};
// Add the request to the RequestQueue.
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(getActivity().getApplicationContext());
// Adiciona a requisição á fila de requisições
fila.add(req);
}
Aggregations