Search in sources :

Example 86 with Response

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

the class FragmentRele method UpdateRele4.

public void UpdateRele4(JSONObject json, String URLUPDATE) {
    URLUPDATE = URLUPDATE + rele4.getIdRele();
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.PUT, URLUPDATE, json, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            Toast.makeText(getActivity(), "Configuração Relê: Atualizado com sucesso !", Toast.LENGTH_SHORT).show();
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getActivity(), "Configuração Relê: 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 87 with Response

use of com.android.volley.Response 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);
}
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) Aplicativo(model.Aplicativo) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 88 with Response

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

Example 89 with Response

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

the class FragmentArduino 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) {
            //obtem a instancia do arduino
            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() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getActivity(), "Configuração Arduino: 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) Arduino(model.Arduino)

Example 90 with Response

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

the class FragmentSensor method GetTemperatura.

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

        @Override
        public void onResponse(JSONObject response) {
            try {
                temp.setIdTemperatura(response.getInt("id"));
                temp.setNome(response.getString("nome"));
                temp.setDescricao(response.getString("descricao"));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getActivity(), "Configuração Temperatura: 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)

Aggregations

Response (com.android.volley.Response)110 VolleyError (com.android.volley.VolleyError)108 JSONObject (org.json.JSONObject)80 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)60 RequestQueue (com.android.volley.RequestQueue)58 HashMap (java.util.HashMap)57 JSONException (org.json.JSONException)57 User (model.User)49 JSONArray (org.json.JSONArray)29 CustomRequestArray (dz.easy.androidclient.Util.CustomRequestArray)18 Context (android.content.Context)17 Toast (android.widget.Toast)17 StringRequest (com.android.volley.toolbox.StringRequest)14 TextView (android.widget.TextView)9 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