use of com.android.volley.toolbox.JsonObjectRequest in project aplicativo by InCasa.
the class HomeActivity method getRele4.
public void getRele4(String URLGETRELE4) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETRELE4, null, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
try {
Rele4.setIdRele(response.getInt("id"));
Rele4.setNome(response.getString("nome"));
Rele4.setDescricao(response.getString("descricao"));
Rele4.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);
}
use of com.android.volley.toolbox.JsonObjectRequest 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 com.android.volley.toolbox.JsonObjectRequest in project aplicativo by InCasa.
the class FragmentArduino method UpdateConfig.
public void UpdateConfig(JSONObject json, String URLUPDATE) {
final Arduino arduino = Arduino.getInstancia();
URLUPDATE = URLUPDATE + arduino.getIdArduino();
JsonObjectRequest req = new JsonObjectRequest(Request.Method.PUT, URLUPDATE, json, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(getActivity(), "Configuração Arduino: Atualizado com sucesso !", Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Arduino: 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.toolbox.JsonObjectRequest in project aplicativo by InCasa.
the class CadastroActivity method Cadastro.
public void Cadastro(JSONObject json, String URLCADASTRO) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, URLCADASTRO, json, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Intent it = new Intent(CadastroActivity.this, LoginActivity.class);
startActivity(it);
}
}, 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();
}
});
// Add the request to the RequestQueue.
// 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.toolbox.JsonObjectRequest 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);
}
Aggregations