Search in sources :

Example 31 with Response

use of com.android.volley.Response 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);
}
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 32 with Response

use of com.android.volley.Response 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 33 with Response

use of com.android.volley.Response in project aplicativo by InCasa.

the class HomeActivity 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) {
            User user = User.getInstancia();
            try {
                user.setNome(response.getString("nome"));
                user.setId(response.getString("id"));
            } 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)

Example 34 with Response

use of com.android.volley.Response in project aplicativo by InCasa.

the class HomeActivity method getSensorPresenca.

public void getSensorPresenca(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 {
                Presenca presenca = Presenca.getInstancia();
                presenca.setIdPresenca(response.getInt("id"));
                presenca.setNome(response.getString("nome"));
                presenca.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) JSONException(org.json.JSONException) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) Presenca(model.Presenca) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 35 with Response

use of com.android.volley.Response 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

Response (com.android.volley.Response)111 VolleyError (com.android.volley.VolleyError)109 JSONObject (org.json.JSONObject)81 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)61 RequestQueue (com.android.volley.RequestQueue)59 HashMap (java.util.HashMap)58 JSONException (org.json.JSONException)58 User (model.User)50 JSONArray (org.json.JSONArray)29 Context (android.content.Context)18 Toast (android.widget.Toast)18 CustomRequestArray (dz.easy.androidclient.Util.CustomRequestArray)18 StringRequest (com.android.volley.toolbox.StringRequest)14 TextView (android.widget.TextView)10 CustomRequest (dz.easy.androidclient.Util.CustomRequest)9 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 Intent (android.content.Intent)6 GridLayoutManager (android.support.v7.widget.GridLayoutManager)6 JsonArrayRequest (com.android.volley.toolbox.JsonArrayRequest)6 MaterialViewPagerHeaderDecorator (com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator)5