Search in sources :

Example 1 with User

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

Example 2 with User

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

Example 3 with User

use of Model.User in project aplicativo by InCasa.

the class HomeActivity method getArduino.

public void getArduino(String URLGETARDUINO) {
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETARDUINO, null, new Response.Listener<JSONObject>() {

        //Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            Arduino arduino = Arduino.getInstancia();
            //adiciona as informações no objeto arduino
            try {
                arduino.setIdArduino(response.getInt("id"));
                arduino.setIp(response.getString("ip"));
                arduino.setMac(response.getString("mac"));
                arduino.setMask(response.getString("mask"));
                arduino.setGateway(response.getString("gateway"));
                arduino.setPorta(response.getString("porta"));
                arduino.setPinoRele1(response.getString("PinoRele1"));
                arduino.setPinoRele2(response.getString("PinoRele2"));
                arduino.setPinoRele3(response.getString("PinoRele3"));
                arduino.setPinoRele4(response.getString("PinoRele4"));
                arduino.setPinoDHT22(response.getString("PinoDHT"));
                arduino.setPinoLDR(response.getString("PinoLDR"));
                arduino.setPinoPresenca(response.getString("PinoPresenca"));
            } 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);
}
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) Arduino(model.Arduino)

Example 4 with User

use of Model.User in project aplicativo by InCasa.

the class HomeActivity method getSensorTemperatura.

public void getSensorTemperatura(String URLGETTEMPERATURA) {
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETTEMPERATURA, null, new Response.Listener<JSONObject>() {

        //Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            try {
                Temperatura temp = Temperatura.getInstancia();
                temp.setIdTemperatura(response.getInt("id"));
                temp.setNome(response.getString("nome"));
                temp.setDescricao(response.getString("descricao"));
            } 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);
}
Also used : VolleyError(com.android.volley.VolleyError) User(model.User) HashMap(java.util.HashMap) Temperatura(model.Temperatura) 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 5 with User

use of Model.User in project aplicativo by InCasa.

the class HomeActivity method getRele1.

public void getRele1(String URLGETRELE1) {
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETRELE1, null, new Response.Listener<JSONObject>() {

        //Em caso de sucesso
        @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() {

        //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);
}
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)

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