Search in sources :

Example 46 with Response

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

the class FragmentRele method UpdateRele2.

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

        @Override
        public void onResponse(JSONObject response) {
        }
    }, 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 47 with Response

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

the class FragmentRele method UpdateRele3.

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

        @Override
        public void onResponse(JSONObject response) {
        }
    }, 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 48 with Response

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

the class FragmentRele method GetRele4.

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

        @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();
            }
            Toast.makeText(getActivity(), "Configuração Relê: Sucesso!", Toast.LENGTH_SHORT).show();
        }
    }, new Response.ErrorListener() {

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

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

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

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