Search in sources :

Example 1 with RequestQueue

use of com.android.volley.RequestQueue in project Space-Station-Tracker by Kiarasht.

the class Locations method displayPasses.

/**
     * After successfully getting a city and country from the last JSON parsing, search a database
     * to see when ISS will pass by this city, country.
     */
public List<Date> displayPasses(final String latitude, final String longitude, final Context applicationContext) {
    // Used for Alert service
    final List<Date> passes = new ArrayList<>();
    final String url;
    if (latitude == null && longitude == null) {
        // Location.java is calling this method
        url = "http://api.open-notify.org/iss-pass.json?lat=" + mLatitude + "&lon=" + mLongitude + "&n=20";
    } else {
        // Alert.java is calling this method
        url = "http://api.open-notify.org/iss-pass.json?lat=" + latitude + "&lon=" + longitude;
    }
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            try {
                final JSONArray results = response.getJSONArray("response");
                final List<SightSee> dates = new ArrayList<>();
                for (int i = 0; i < results.length(); ++i) {
                    final JSONObject aPass = results.getJSONObject(i);
                    passes.add(new Date(Long.parseLong(aPass.getString("risetime")) * 1000L));
                    final SightSee aSightSee = new SightSee(aPass.getInt("duration"), aPass.getInt("risetime"));
                    dates.add(aSightSee);
                }
                final View headerView = LayoutInflater.from(mActivity).inflate(R.layout.locations_header, null);
                headerView.post(new Runnable() {

                    @Override
                    public void run() {
                        headerView.getLayoutParams().height = mFlexibleSpaceImageHeight;
                    }
                });
                mAdapter = new LocationAdapter(mActivity, headerView);
                mAdapter.setDataSet(dates);
                mRecyclerView.setAdapter(mAdapter);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError e) {
            if (latitude == null && longitude == null) {
                Toast.makeText(Locations.this, R.string.errorConnection, Toast.LENGTH_LONG).show();
            }
        }
    });
    // If Alert.java called us
    if (requestQueue == null) {
        RequestQueue requestQueue = Volley.newRequestQueue(applicationContext);
        requestQueue.add(jsonObjectRequest);
    } else {
        // If Locations.java called us
        jsonObjectRequest.setTag(TAG);
        requestQueue.add(jsonObjectRequest);
    }
    // Only Alert.java benefits from this return
    return passes;
}
Also used : VolleyError(com.android.volley.VolleyError) LocationAdapter(com.restart.spacestationtracker.adapter.LocationAdapter) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ImageView(android.widget.ImageView) ObservableRecyclerView(com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView) View(android.view.View) AdView(com.google.android.gms.ads.AdView) TextView(android.widget.TextView) Date(java.util.Date) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) SightSee(com.restart.spacestationtracker.data.SightSee) RequestQueue(com.android.volley.RequestQueue) ArrayList(java.util.ArrayList) List(java.util.List) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 2 with RequestQueue

use of com.android.volley.RequestQueue in project DogeTracker_Android by avrland.

the class wallet_balance method getWalletBalance.

// We download here json response, leaving a information everything is ready to update view
public void getWalletBalance(final Context currentContext, final Handler walletBalanceHandler, String address) {
    StringRequest request = new StringRequest(url + address, new Response.Listener<String>() {

        @Override
        public void onResponse(String string) {
            parseJsonData(string);
            // We're ready, leave messenge for handler to refresh_rates in view
            // It doesn't matter now what kind of messege we send.
            Message news = new Message();
            news.arg1 = 1;
            walletBalanceHandler.sendMessage(news);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
        // If something went wrong, we leave messege with error
        }
    });
    RequestQueue rQueue = Volley.newRequestQueue(currentContext);
    rQueue.add(request);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) Message(android.os.Message) RequestQueue(com.android.volley.RequestQueue) StringRequest(com.android.volley.toolbox.StringRequest)

Example 3 with RequestQueue

use of com.android.volley.RequestQueue in project DogeTracker_Android by avrland.

the class doge_rates method getRates.

// We download here json response, leaving a information everything is ready to update view
public void getRates(final Handler handler, final String fiatCurrency) {
    DIALOG = new ProgressDialog(CURRENT_CONTEXT);
    StringRequest request = new StringRequest(URL + "?convert=" + fiatCurrency.toLowerCase(), new Response.Listener<String>() {

        @Override
        public void onResponse(String string) {
            parseJsonData(string, fiatCurrency.toLowerCase());
            // We're ready, leave messenge for handler to refresh_rates in view
            // It doesn't matter now what kind of messege we send.
            Message news = new Message();
            news.arg1 = 1;
            handler.sendMessage(news);
            saveRatesToOffline();
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            Message news = new Message();
            news.arg1 = 0;
            handler.sendMessage(news);
            readRatesFromOffline();
        }
    });
    RequestQueue rQueue = Volley.newRequestQueue(CURRENT_CONTEXT);
    rQueue.add(request);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) Message(android.os.Message) RequestQueue(com.android.volley.RequestQueue) StringRequest(com.android.volley.toolbox.StringRequest) ProgressDialog(android.app.ProgressDialog)

Example 4 with RequestQueue

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

the class ContentActivity method checkCount.

private void checkCount(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);
                }
            }// 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) GraphResponse(com.facebook.GraphResponse) 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 5 with RequestQueue

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

the class EventRegister method addTicket.

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

        @Override
        public void onResponse(String response) {
            try {
                JSONObject obj1 = new JSONObject(response);
                JSONArray ticketDetails = obj1.getJSONArray("data");
                for (int i = 0; i < ticketDetails.length(); i++) {
                    JSONObject obj2 = ticketDetails.getJSONObject(i);
                    if (obj2.getString("eventid").equals(eventId)) {
                        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"));
                        databaseController.addTicketsToDb(TicketModel);
                    }
                }
            }// 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) {
        }
    });
    queue.add(request);
}
Also used : Response(com.android.volley.Response) MyNotificationResponse(com.manan.dev.ec2018app.Notifications.MyNotificationResponse) 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)

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