Search in sources :

Example 36 with User

use of model.User in project aplicativo by InCasa.

the class FragmentCelular 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 Celular: Configuração salva com Sucesso !", Toast.LENGTH_SHORT).show();
        }
    }, new Response.ErrorListener() {

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

use of model.User in project aplicativo by InCasa.

the class FragmentSensor method UpdateLuminosidade.

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

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

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

use of model.User in project aplicativo by InCasa.

the class AdminActivity method getUserInfo.

public void getUserInfo(JSONObject json, String URLUSERINFO) {
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLUSERINFO, json, new Response.Listener<JSONObject>() {

        //Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            Context context = getApplicationContext();
            CharSequence text = "Usuário: Sucesso !";
            int duration = Toast.LENGTH_SHORT;
            User user = User.getInstancia();
            try {
                user.setNome(response.getString("nome"));
                user.setId(response.getString("id"));
            } catch (JSONException e) {
                e.printStackTrace();
            }
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }
    }, new Response.ErrorListener() {

        //Em caso de erro
        @Override
        public void onErrorResponse(VolleyError error) {
            Context context = getApplicationContext();
            CharSequence text = "Usuário: Falha !";
            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 : 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 39 with User

use of model.User in project aplicativo by InCasa.

the class HomeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    exibeTelaPrincipalOuSolicitaLogin();
    setContentView(R.layout.activity_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    SharedPreferences mSharedPreferences = getSharedPreferences("ServerAdress", 0);
    this.ip = mSharedPreferences.getString("servidor", " ");
    String URLTEMPERATURA = "http://" + ip + "/backend/temperaturaValor";
    String URLUMIDADE = "http://" + ip + "/backend/umidadeValor";
    getTemperatura(URLTEMPERATURA);
    getUmidade(URLUMIDADE);
    String URLGETTEMPERATURA = "http://" + ip + "/backend/temperatura/1";
    String URLGETUMIDADE = "http://" + ip + "/backend/umidade/1";
    String URLGETPRESENCA = "http://" + ip + "/backend/presenca/1";
    String URLGETLUMINOSISADE = "http://" + ip + "/backend/luminosidade/1";
    getSensorTemperatura(URLGETTEMPERATURA);
    getSensorUmidade(URLGETUMIDADE);
    getSensorPresenca(URLGETPRESENCA);
    getSensorLuminosidade(URLGETLUMINOSISADE);
    String URLGETARDUINO = "http://" + ip + "/backend/arduino/1";
    getArduino(URLGETARDUINO);
    String URLGETCELULAR = "http://" + ip + "/backend/aplicativo/1";
    getCelular(URLGETCELULAR);
    JSONObject jsonBody = new JSONObject();
    User user = User.getInstancia();
    try {
        jsonBody.put("login", user.getLogin());
        jsonBody.put("senha", user.getSenha());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    String URLUSER = "http://" + ip + "/backend/getUser";
    getUser(jsonBody, URLUSER);
    String URLGETRELE1 = "http://" + ip + "/backend/rele/1";
    String URLGETRELE2 = "http://" + ip + "/backend/rele/2";
    String URLGETRELE3 = "http://" + ip + "/backend/rele/3";
    String URLGETRELE4 = "http://" + ip + "/backend/rele/4";
    getRele1(URLGETRELE1);
    getRele2(URLGETRELE2);
    getRele3(URLGETRELE3);
    getRele4(URLGETRELE4);
}
Also used : NavigationView(android.support.design.widget.NavigationView) User(model.User) JSONObject(org.json.JSONObject) SharedPreferences(android.content.SharedPreferences) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) JSONException(org.json.JSONException) DrawerLayout(android.support.v4.widget.DrawerLayout) Toolbar(android.support.v7.widget.Toolbar)

Example 40 with User

use of model.User in project aplicativo by InCasa.

the class AdminActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_admin);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    userNome = (EditText) findViewById(R.id.userNome);
    userLogin = (EditText) findViewById(R.id.userLogin);
    userSenhaAnt = (EditText) findViewById(R.id.userSenhaAnt);
    userSenhaNov = (EditText) findViewById(R.id.userSenhaNov);
    userSenhaC = (EditText) findViewById(R.id.userSenhaC);
    Button submitUser = (Button) findViewById(R.id.btnAdm);
    SharedPreferences mSharedPreferences = getSharedPreferences("ServerAdress", 0);
    this.ip = mSharedPreferences.getString("servidor", " ");
    String URLUSER = "http://" + ip + "/backend/getUser";
    JSONObject jsonBody = new JSONObject();
    User user = User.getInstancia();
    try {
        jsonBody.put("login", user.getLogin());
        jsonBody.put("senha", user.getSenha());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    getUser(jsonBody, URLUSER);
    userNome.setText(user.getNome());
    userLogin.setText(user.getLogin());
    submitUser.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            submit();
        }
    });
}
Also used : User(model.User) JSONObject(org.json.JSONObject) Button(android.widget.Button) SharedPreferences(android.content.SharedPreferences) JSONException(org.json.JSONException) View(android.view.View)

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