use of model.Aplicativo in project aplicativo by InCasa.
the class FragmentCelular 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) {
try {
Aplicativo app = Aplicativo.getInstancia();
app.setIdAplicativo(response.getInt("id"));
app.setNome(response.getString("nome"));
app.setMac(response.getString("mac"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Celular: 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 model.Aplicativo in project aplicativo by InCasa.
the class FragmentCelular method UpdateConfig.
public void UpdateConfig(JSONObject json, String URLUPDATE) {
final Aplicativo app = Aplicativo.getInstancia();
URLUPDATE = URLUPDATE + app.getIdAplicativo();
JsonObjectRequest req = new JsonObjectRequest(Request.Method.PUT, URLUPDATE, json, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(getActivity(), "Configuração Celular: Atualizado com sucesso !", Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Celular: 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 model.Aplicativo in project aplicativo by InCasa.
the class FragmentCelular method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final EditText macAppField = (EditText) getView().findViewById(R.id.editAppMac);
final EditText nameAppField = (EditText) getView().findViewById(R.id.editAppName);
Button btnAppSalvar = (Button) getView().findViewById(R.id.btnAppSalvar);
Button btnCloneMac = (Button) getView().findViewById(R.id.btnCloneMAC);
SharedPreferences mSharedPreferences = this.getActivity().getSharedPreferences("ServerAdress", 0);
String ip = mSharedPreferences.getString("servidor", null);
final String URLCADASTRO = "http://" + ip + "/backend/aplicativo";
final String URLGET = "http://" + ip + "/backend/aplicativo/1";
final String URLUPDATE = "http://" + ip + "/backend/aplicativo/update/";
GetConfig(URLGET);
//seta as informações do objeto nos editText
Aplicativo app = Aplicativo.getInstancia();
macAppField.setText(app.getMac());
nameAppField.setText(app.getNome());
btnCloneMac.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
macAppField.setText(getMacAddr());
}
});
btnAppSalvar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Aplicativo app = Aplicativo.getInstancia();
String nome = nameAppField.getText().toString();
String mac = macAppField.getText().toString();
if (TextUtils.isEmpty(nome) || TextUtils.isEmpty(mac)) {
if (TextUtils.isEmpty(nome)) {
nameAppField.setError("Preencha o campo nome");
}
if (TextUtils.isEmpty(mac)) {
macAppField.setError("Preencha o campo MAC");
}
} else {
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put("mac", mac);
app.setMac(mac);
jsonBody.put("nome", nome);
app.setNome(nome);
} catch (JSONException e) {
e.printStackTrace();
}
//SaveConfig(jsonBody, URLCADASTRO);
UpdateConfig(jsonBody, URLUPDATE);
}
}
});
}
use of model.Aplicativo in project aplicativo by InCasa.
the class HomeActivity method getCelular.
public void getCelular(String URLGETCELULAR) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETCELULAR, null, new Response.Listener<JSONObject>() {
//Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
try {
Aplicativo app = Aplicativo.getInstancia();
app.setIdAplicativo(response.getInt("id"));
app.setNome(response.getString("nome"));
app.setMac(response.getString("mac"));
} 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