Search in sources :

Example 66 with Response

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

the class SensorActivity method getTemperatura.

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

        // Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            String temp = "";
            try {
                TextView txtTemp = (TextView) findViewById(R.id.txtTemp);
                temp = response.getString("valor");
                if (temp.equals("null")) {
                    txtTemp.setText("N/A");
                } else {
                    temp = temp + " ºC";
                    txtTemp.setText(temp);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {

        // Em caso de erro
        @Override
        public void onErrorResponse(VolleyError error) {
            Context context = getApplicationContext();
            CharSequence text = "Erro na requisição";
            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(context, text, duration);
            toast.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;
        }
    };
    // 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) Context(android.content.Context) 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) TextView(android.widget.TextView) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 67 with Response

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

the class ServerActivity method testeServer.

public void testeServer(final String ipServer) {
    final ProgressBar bar = (ProgressBar) findViewById(R.id.progressBar);
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, "http://" + ipServer + "/backend/teste", null, new Response.Listener<JSONObject>() {

        // Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            bar.setProgress(60);
            Context context = getApplicationContext();
            CharSequence text = "Servidor: OK";
            int duration = Toast.LENGTH_SHORT;
            saveServer(ipServer);
            bar.setProgress(80);
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
            bar.setProgress(100);
            Intent it = new Intent(ServerActivity.this, LoginActivity.class);
            startActivity(it);
        }
    }, new Response.ErrorListener() {

        // Em caso de erro
        @Override
        public void onErrorResponse(VolleyError error) {
            Context context = getApplicationContext();
            CharSequence text = "Erro no servidor";
            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
            bar.setProgress(0);
        }
    });
    // 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) Intent(android.content.Intent) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) Toast(android.widget.Toast) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) ProgressBar(android.widget.ProgressBar)

Example 68 with Response

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

the class FragmentArduino method SaveConfig.

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

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

        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getActivity(), "Configuração Arduino: Erro ao salvar a configuraçã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 69 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 70 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)

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