Search in sources :

Example 26 with RequestQueue

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

the class VozActivity method enviaComando.

public void enviaComando(JSONObject json, String URLCOMANDO) {
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, URLCOMANDO, json, new Response.Listener<JSONObject>() {

        // Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            Context context = getApplicationContext();
            CharSequence text = "Comando enviado";
            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
            try {
                String resposta = response.getString("valor");
                txtSpeechOutput.setText(resposta);
                txtSpeechInput.setText("");
            } 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 : Context(android.content.Context) 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) Toast(android.widget.Toast) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 27 with RequestQueue

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

the class FragmentArduino method UpdateConfig.

public void UpdateConfig(JSONObject json, String URLUPDATE) {
    final Arduino arduino = Arduino.getInstancia();
    URLUPDATE = URLUPDATE + arduino.getIdArduino();
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.PUT, URLUPDATE, json, new Response.Listener<JSONObject>() {

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

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

Example 28 with RequestQueue

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

the class FragmentRele method UpdateRele1.

public void UpdateRele1(JSONObject json, String URLUPDATE) {
    URLUPDATE = URLUPDATE + rele1.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 29 with RequestQueue

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

the class FragmentRele method GetRele1.

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

        @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() {

        @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 30 with RequestQueue

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

the class FragmentRele method GetRele2.

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

        @Override
        public void onResponse(JSONObject response) {
            try {
                rele2.setIdRele(response.getInt("id"));
                rele2.setNome(response.getString("nome"));
                rele2.setDescricao(response.getString("descricao"));
                rele2.setPorta(response.getInt("porta"));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, 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)

Aggregations

RequestQueue (com.android.volley.RequestQueue)72 Response (com.android.volley.Response)59 VolleyError (com.android.volley.VolleyError)58 JSONObject (org.json.JSONObject)57 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)54 HashMap (java.util.HashMap)51 User (model.User)50 JSONException (org.json.JSONException)40 Context (android.content.Context)18 Toast (android.widget.Toast)18 TextView (android.widget.TextView)11 File (java.io.File)9 Intent (android.content.Intent)7 Network (com.android.volley.Network)7 PackageInfo (android.content.pm.PackageInfo)6 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6 Switch (android.widget.Switch)4 DiskBasedCache (com.android.volley.toolbox.DiskBasedCache)4 View (android.view.View)3 HurlStack (com.android.volley.toolbox.HurlStack)3