Search in sources :

Example 86 with JsonObjectRequest

use of com.android.volley.toolbox.JsonObjectRequest in project aplicativo by InCasa.

the class FragmentSensor method UpdatePresenca.

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

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

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

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

Example 88 with JsonObjectRequest

use of com.android.volley.toolbox.JsonObjectRequest in project aplicativo by InCasa.

the class FragmentSensor method GetUmidade.

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

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

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

use of com.android.volley.toolbox.JsonObjectRequest in project aplicativo by InCasa.

the class FragmentSensor method UpdateUmidade.

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

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

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

use of com.android.volley.toolbox.JsonObjectRequest in project android-volley by mcxiaoke.

the class JsonRequestCharsetTest method defaultCharsetJsonObject.

@Test
public void defaultCharsetJsonObject() throws Exception {
    // UTF-8 is default charset for JSON
    byte[] data = jsonObjectString().getBytes(Charset.forName("UTF-8"));
    NetworkResponse network = new NetworkResponse(data);
    JsonObjectRequest objectRequest = new JsonObjectRequest("", null, null, null);
    Response<JSONObject> objectResponse = objectRequest.parseNetworkResponse(network);
    assertNotNull(objectResponse);
    assertTrue(objectResponse.isSuccess());
    assertEquals(TEXT_VALUE, objectResponse.result.getString(TEXT_NAME));
    assertEquals(COPY_VALUE, objectResponse.result.getString(COPY_NAME));
}
Also used : JSONObject(org.json.JSONObject) NetworkResponse(com.android.volley.NetworkResponse) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) Test(org.junit.Test)

Aggregations

JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)129 JSONObject (org.json.JSONObject)124 VolleyError (com.android.volley.VolleyError)102 Response (com.android.volley.Response)101 RequestQueue (com.android.volley.RequestQueue)70 HashMap (java.util.HashMap)66 JSONException (org.json.JSONException)59 User (model.User)50 Gson (com.google.gson.Gson)30 Test (org.junit.Test)22 Context (android.content.Context)19 Toast (android.widget.Toast)17 GsonBuilder (com.google.gson.GsonBuilder)17 NetworkResponse (com.android.volley.NetworkResponse)16 DefaultRetryPolicy (com.android.volley.DefaultRetryPolicy)12 TextView (android.widget.TextView)11 Wallet (it.angelic.mpw.model.jsonpojos.wallet.Wallet)9 ExecutionException (java.util.concurrent.ExecutionException)8 HomeStats (it.angelic.mpw.model.jsonpojos.home.HomeStats)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7