use of model.User in project aplicativo by InCasa.
the class FragmentCelular 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 Celular: Configuração salva com Sucesso !", Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Celular: 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 model.User 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);
}
use of model.User in project aplicativo by InCasa.
the class AdminActivity method getUserInfo.
public void getUserInfo(JSONObject json, String URLUSERINFO) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLUSERINFO, 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);
}
use of model.User in project aplicativo by InCasa.
the class HomeActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
exibeTelaPrincipalOuSolicitaLogin();
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
SharedPreferences mSharedPreferences = getSharedPreferences("ServerAdress", 0);
this.ip = mSharedPreferences.getString("servidor", " ");
String URLTEMPERATURA = "http://" + ip + "/backend/temperaturaValor";
String URLUMIDADE = "http://" + ip + "/backend/umidadeValor";
getTemperatura(URLTEMPERATURA);
getUmidade(URLUMIDADE);
String URLGETTEMPERATURA = "http://" + ip + "/backend/temperatura/1";
String URLGETUMIDADE = "http://" + ip + "/backend/umidade/1";
String URLGETPRESENCA = "http://" + ip + "/backend/presenca/1";
String URLGETLUMINOSISADE = "http://" + ip + "/backend/luminosidade/1";
getSensorTemperatura(URLGETTEMPERATURA);
getSensorUmidade(URLGETUMIDADE);
getSensorPresenca(URLGETPRESENCA);
getSensorLuminosidade(URLGETLUMINOSISADE);
String URLGETARDUINO = "http://" + ip + "/backend/arduino/1";
getArduino(URLGETARDUINO);
String URLGETCELULAR = "http://" + ip + "/backend/aplicativo/1";
getCelular(URLGETCELULAR);
JSONObject jsonBody = new JSONObject();
User user = User.getInstancia();
try {
jsonBody.put("login", user.getLogin());
jsonBody.put("senha", user.getSenha());
} catch (JSONException e) {
e.printStackTrace();
}
String URLUSER = "http://" + ip + "/backend/getUser";
getUser(jsonBody, URLUSER);
String URLGETRELE1 = "http://" + ip + "/backend/rele/1";
String URLGETRELE2 = "http://" + ip + "/backend/rele/2";
String URLGETRELE3 = "http://" + ip + "/backend/rele/3";
String URLGETRELE4 = "http://" + ip + "/backend/rele/4";
getRele1(URLGETRELE1);
getRele2(URLGETRELE2);
getRele3(URLGETRELE3);
getRele4(URLGETRELE4);
}
use of model.User in project aplicativo by InCasa.
the class AdminActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
userNome = (EditText) findViewById(R.id.userNome);
userLogin = (EditText) findViewById(R.id.userLogin);
userSenhaAnt = (EditText) findViewById(R.id.userSenhaAnt);
userSenhaNov = (EditText) findViewById(R.id.userSenhaNov);
userSenhaC = (EditText) findViewById(R.id.userSenhaC);
Button submitUser = (Button) findViewById(R.id.btnAdm);
SharedPreferences mSharedPreferences = getSharedPreferences("ServerAdress", 0);
this.ip = mSharedPreferences.getString("servidor", " ");
String URLUSER = "http://" + ip + "/backend/getUser";
JSONObject jsonBody = new JSONObject();
User user = User.getInstancia();
try {
jsonBody.put("login", user.getLogin());
jsonBody.put("senha", user.getSenha());
} catch (JSONException e) {
e.printStackTrace();
}
getUser(jsonBody, URLUSER);
userNome.setText(user.getNome());
userLogin.setText(user.getLogin());
submitUser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
submit();
}
});
}
Aggregations