use of com.android.volley.Response in project aplicativo by InCasa.
the class FragmentRele method GetRele1.
public void GetRele1(String URLGETRELE1) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETRELE1, null, new Response.Listener<JSONObject>() {
@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() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Relê: 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.Response in project aplicativo by InCasa.
the class FragmentSensor method GetLuminosidade.
public void GetLuminosidade(String URLGETLUMINOSISADE) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETLUMINOSISADE, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
lumi.setIdLuminosidade(response.getInt("id"));
lumi.setNome(response.getString("nome"));
lumi.setDescricao(response.getString("descricao"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Luminosidade: 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.Response in project aplicativo by InCasa.
the class FragmentSensor method UpdateTemperatura.
public void UpdateTemperatura(JSONObject json, String URLUPDATE) {
URLUPDATE = URLUPDATE + temp.getIdTemperatura();
JsonObjectRequest req = new JsonObjectRequest(Request.Method.PUT, URLUPDATE, json, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(getActivity(), "Configuração Temperatura: Atualizado com sucesso !", Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Temperatura: 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);
}
use of com.android.volley.Response in project aplicativo by InCasa.
the class FragmentServidor method testeServer.
public void testeServer(String ipServer) {
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) {
Toast.makeText(getActivity(), "Servidor: OK", Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
//Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Erro no servidor", Toast.LENGTH_SHORT).show();
}
});
//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.Response in project aplicativo by InCasa.
the class AdminActivity method getUser.
public void getUser(JSONObject json, String URLUSER) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, URLUSER, json, new Response.Listener<JSONObject>() {
//Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
Context context = getApplicationContext();
CharSequence text = "Usuário: Sucesso !";
int duration = Toast.LENGTH_SHORT;
User user = User.getInstancia();
try {
user.setNome(response.getString("nome"));
user.setId(response.getString("id"));
} catch (JSONException e) {
e.printStackTrace();
}
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}, new Response.ErrorListener() {
//Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
Context context = getApplicationContext();
CharSequence text = "Usuário: Falha !";
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);
}
Aggregations