Search in sources :

Example 6 with User

use of model.User in project aplicativo by InCasa.

the class HomeActivity method getUser.

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

        //Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            User user = User.getInstancia();
            try {
                user.setNome(response.getString("nome"));
                user.setId(response.getString("id"));
            } 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 : 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 7 with User

use of model.User in project aplicativo by InCasa.

the class HomeActivity method getSensorPresenca.

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

        //Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            try {
                Presenca presenca = Presenca.getInstancia();
                presenca.setIdPresenca(response.getInt("id"));
                presenca.setNome(response.getString("nome"));
                presenca.setDescricao(response.getString("descricao"));
            } 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 : 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) Presenca(model.Presenca) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 8 with User

use of model.User in project aplicativo by InCasa.

the class HomeActivity 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) {
        }
    }) {

        @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) 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) TextView(android.widget.TextView) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 9 with User

use of model.User in project aplicativo by InCasa.

the class HomeActivity method getRele4.

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

        //Em caso de sucesso
        @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();
            }
        }
    }, 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 : 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 10 with User

use of model.User in project aplicativo by InCasa.

the class FragmentRele method GetRele3.

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

        @Override
        public void onResponse(JSONObject response) {
            try {
                rele3.setIdRele(response.getInt("id"));
                rele3.setNome(response.getString("nome"));
                rele3.setDescricao(response.getString("descricao"));
                rele3.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

User (model.User)52 JSONObject (org.json.JSONObject)52 RequestQueue (com.android.volley.RequestQueue)49 Response (com.android.volley.Response)49 VolleyError (com.android.volley.VolleyError)49 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)49 HashMap (java.util.HashMap)49 JSONException (org.json.JSONException)38 Context (android.content.Context)15 Toast (android.widget.Toast)15 TextView (android.widget.TextView)6 Switch (android.widget.Switch)4 Intent (android.content.Intent)3 Aplicativo (model.Aplicativo)3 Arduino (model.Arduino)3 SharedPreferences (android.content.SharedPreferences)2 NavigationView (android.support.design.widget.NavigationView)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 Toolbar (android.support.v7.widget.Toolbar)1