Search in sources :

Example 21 with User

use of Model.User 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 22 with User

use of Model.User in project aplicativo by InCasa.

the class SensorActivity method getLuminosidade.

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

        //Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            String lumi = "";
            try {
                TextView txtLumi = (TextView) findViewById(R.id.txtLumi);
                lumi = response.getString("valor");
                if (lumi.equals("null")) {
                    txtLumi.setText("N/A");
                } else {
                    lumi = lumi + "%";
                    txtLumi.setText(lumi);
                }
            } 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 23 with User

use of Model.User in project aplicativo by InCasa.

the class SensorActivity method getUmidade.

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

        //Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            String umi = "";
            try {
                TextView txtUmi = (TextView) findViewById(R.id.txtUmi);
                umi = response.getString("valor");
                if (umi.equals("null")) {
                    txtUmi.setText("N/A");
                } else {
                    txtUmi.setText(umi);
                }
            } 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 24 with User

use of Model.User 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 25 with User

use of Model.User 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)

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