Search in sources :

Example 16 with User

use of Model.User 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);
}
Also used : VolleyError(com.android.volley.VolleyError) User(model.User) HashMap(java.util.HashMap) JSONException(org.json.JSONException) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 17 with User

use of Model.User 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);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) User(model.User) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 18 with User

use of Model.User in project aplicativo by InCasa.

the class AdminActivity method submit.

public void submit() {
    String nome = userNome.getText().toString();
    String login = userLogin.getText().toString();
    String senhaAnt = userSenhaAnt.getText().toString();
    String senhaNov = userSenhaNov.getText().toString();
    String senhaC = userSenhaC.getText().toString();
    String PUTUSER = "http://" + ip + "/backend/user/update/";
    if (TextUtils.isEmpty(nome) || TextUtils.isEmpty(login) || TextUtils.isEmpty(senhaAnt) || TextUtils.isEmpty(senhaNov) || TextUtils.isEmpty(senhaC)) {
        if (TextUtils.isEmpty(nome)) {
            userNome.setError("Preencha o campo nome");
            return;
        }
        if (TextUtils.isEmpty(login)) {
            userNome.setError("Preencha o campo login");
            return;
        }
        if (TextUtils.isEmpty(senhaAnt)) {
            userSenhaAnt.setError("Preencha o campo senha antiga");
            return;
        }
        if (TextUtils.isEmpty(senhaNov)) {
            userSenhaNov.setError("Preencha o campo de senha nova");
            return;
        }
        if (TextUtils.isEmpty(senhaC)) {
            userSenhaC.setError("Preencha o campo confirmação de senha nova");
            return;
        }
    } else {
        if (senhaNov.equals(senhaC)) {
            //Criação do Json da requisição
            JSONObject jsonBody = new JSONObject();
            try {
                User user = User.getInstancia();
                jsonBody.put("login", user.getLogin());
                jsonBody.put("senha", user.getSenha());
            } catch (JSONException e) {
                e.printStackTrace();
            }
            JSONObject jsonBody2 = new JSONObject();
            try {
                jsonBody2.put("nome", nome);
                jsonBody2.put("login", login);
                jsonBody2.put("senha", senhaNov);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            atualizar(jsonBody2, PUTUSER);
            Intent it = new Intent(this, LoginActivity.class);
            startActivity(it);
            this.finish();
        } else {
            Context context = getApplicationContext();
            CharSequence text = "As senhas devem ser iguais";
            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }
    }
}
Also used : Context(android.content.Context) User(model.User) JSONObject(org.json.JSONObject) Toast(android.widget.Toast) JSONException(org.json.JSONException) Intent(android.content.Intent)

Example 19 with User

use of Model.User 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);
}
Also used : Context(android.content.Context) VolleyError(com.android.volley.VolleyError) User(model.User) HashMap(java.util.HashMap) JSONException(org.json.JSONException) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) Toast(android.widget.Toast) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 20 with User

use of Model.User in project aplicativo by InCasa.

the class AdminActivity method atualizar.

public void atualizar(JSONObject json, String PUTUSER) {
    User user = User.getInstancia();
    PUTUSER = PUTUSER + user.getId();
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.PUT, PUTUSER, json, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            Context context = getApplicationContext();
            CharSequence text = "Administrador: Dados atualizados com sucesso !";
            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
            Intent it = new Intent(AdminActivity.this, LoginActivity.class);
            startActivity(it);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Context context = getApplicationContext();
            CharSequence text = "Administrador: Falha ao atualizar !";
            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;
        }
    };
    // 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);
}
Also used : Context(android.content.Context) VolleyError(com.android.volley.VolleyError) User(model.User) HashMap(java.util.HashMap) Intent(android.content.Intent) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) Toast(android.widget.Toast) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Aggregations

User (model.User)52 JSONObject (org.json.JSONObject)52 RequestQueue (com.android.volley.RequestQueue)49 Response (com.android.volley.Response)49 VolleyError (com.android.volley.VolleyError)49 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)49 HashMap (java.util.HashMap)49 JSONException (org.json.JSONException)38 Context (android.content.Context)15 Toast (android.widget.Toast)15 TextView (android.widget.TextView)6 Switch (android.widget.Switch)4 Intent (android.content.Intent)3 Aplicativo (model.Aplicativo)3 Arduino (model.Arduino)3 SharedPreferences (android.content.SharedPreferences)2 NavigationView (android.support.design.widget.NavigationView)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 Toolbar (android.support.v7.widget.Toolbar)1