Search in sources :

Example 76 with RequestQueue

use of com.android.volley.RequestQueue in project EC2018App by Manan-YMCA.

the class RegisterActivity method registerUser.

private void registerUser(final UserDetails userDetails) {
    String url = getResources().getString(R.string.register_user_api);
    RequestQueue queue = Volley.newRequestQueue(this);
    StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            MDToast.makeText(RegisterActivity.this, "Registered!", MDToast.LENGTH_SHORT, MDToast.TYPE_SUCCESS).show();
            mProgress.dismiss();
            SharedPreferences.Editor editor = getSharedPreferences(getResources().getString(R.string.sharedPrefName), MODE_PRIVATE).edit();
            editor.putString("Phone", userDetails.getmPhone());
            editor.apply();
            AccessToken token = AccessToken.getCurrentAccessToken();
            if (token != null) {
                startSession();
            } else {
                FragmentManager fm = getFragmentManager();
                FragmentFbLogin fbLogin = new FragmentFbLogin();
                fbLogin.show(fm, "fbLoginFragment");
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            mProgress.dismiss();
        }
    }) {

        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> map = new HashMap<String, String>();
            map.put("name", userDetails.getmName());
            map.put("email", userDetails.getEmail());
            map.put("phone", userDetails.getmPhone());
            map.put("college", userDetails.getmCollege());
            map.put("fb", userDetails.getmFbId());
            return map;
        }
    };
    queue.add(request);
}
Also used : FragmentFbLogin(com.manan.dev.ec2018app.Fragments.FragmentFbLogin) VolleyError(com.android.volley.VolleyError) HashMap(java.util.HashMap) StringRequest(com.android.volley.toolbox.StringRequest) Response(com.android.volley.Response) FragmentManager(android.app.FragmentManager) RequestQueue(com.android.volley.RequestQueue) AccessToken(com.facebook.AccessToken)

Example 77 with RequestQueue

use of com.android.volley.RequestQueue in project EC2018App by Manan-YMCA.

the class Tickets method reload.

private void reload(final String[] phone) {
    String url = getResources().getString(R.string.get_events_qr_code);
    url += phone;
    RequestQueue queue = Volley.newRequestQueue(this);
    StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            mProgress.dismiss();
            try {
                JSONObject obj1 = new JSONObject(response);
                JSONArray ticketDetails = obj1.getJSONArray("data");
                for (int i = 0; i < ticketDetails.length(); i++) {
                    JSONObject obj2 = ticketDetails.getJSONObject(i);
                    QRTicketModel TicketModel = new QRTicketModel();
                    TicketModel.setPaymentStatus(obj2.getInt("paymentstatus"));
                    TicketModel.setArrivalStatus(obj2.getInt("arrived"));
                    TicketModel.setQRcode(obj2.getString("qrcode"));
                    TicketModel.setEventID(obj2.getString("eventid"));
                    TicketModel.setTimeStamp(obj2.getLong("timestamp"));
                    userTickets.add(TicketModel);
                }
                mIncomingHandler.sendEmptyMessage(0);
            }// Try and catch are included to handle any errors due to JSON
             catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            mProgress.dismiss();
        }
    });
    queue.add(request);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) RequestQueue(com.android.volley.RequestQueue) StringRequest(com.android.volley.toolbox.StringRequest) JSONArray(org.json.JSONArray) QRTicketModel(com.manan.dev.ec2018app.Models.QRTicketModel)

Example 78 with RequestQueue

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

the class ReleActivity method getRele4.

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

        // Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            String temp = "";
            try {
                Switch rele4 = (Switch) findViewById(R.id.switch4);
                temp = response.getString("valor");
                if (temp.equals("0")) {
                    rele4.setChecked(false);
                    estado4 = false;
                } else {
                    rele4.setChecked(true);
                    estado4 = true;
                }
            } 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) Switch(android.widget.Switch) Toast(android.widget.Toast) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 79 with RequestQueue

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

the class ReleActivity method getRele3.

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

        // Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            String temp = "";
            try {
                Switch rele3 = (Switch) findViewById(R.id.switch3);
                temp = response.getString("valor");
                if (temp.equals("0")) {
                    rele3.setChecked(false);
                    estado3 = false;
                } else {
                    rele3.setChecked(true);
                    estado3 = true;
                }
            } 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) Switch(android.widget.Switch) Toast(android.widget.Toast) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 80 with RequestQueue

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

the class ReleActivity method getRele1.

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

        // Em caso de sucesso
        @Override
        public void onResponse(JSONObject response) {
            String temp = "";
            try {
                Switch rele1 = (Switch) findViewById(R.id.switch1);
                temp = response.getString("valor");
                if (temp.equals("0")) {
                    rele1.setChecked(false);
                    estado1 = false;
                } else {
                    rele1.setChecked(true);
                    estado1 = true;
                }
            } 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) Switch(android.widget.Switch) Toast(android.widget.Toast) RequestQueue(com.android.volley.RequestQueue) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Aggregations

RequestQueue (com.android.volley.RequestQueue)119 Response (com.android.volley.Response)101 VolleyError (com.android.volley.VolleyError)95 JSONObject (org.json.JSONObject)83 HashMap (java.util.HashMap)71 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)59 User (model.User)50 JSONException (org.json.JSONException)50 StringRequest (com.android.volley.toolbox.StringRequest)29 Context (android.content.Context)22 Toast (android.widget.Toast)20 TextView (android.widget.TextView)14 Intent (android.content.Intent)10 DefaultRetryPolicy (com.android.volley.DefaultRetryPolicy)10 Network (com.android.volley.Network)10 NetworkResponse (com.android.volley.NetworkResponse)10 File (java.io.File)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 ExecutionException (java.util.concurrent.ExecutionException)9 TimeoutException (java.util.concurrent.TimeoutException)9