Search in sources :

Example 16 with Response

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

the class PeopleinSpace method display_people.

/**
     * Displays a list of astronauts in a RecyclerView
     */
private void display_people() {
    final String url = "http://www.howmanypeopleareinspacerightnow.com/peopleinspace.json";
    final List<Astronaut> peopleInSpace = new ArrayList<>();
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            try {
                LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL, false);
                mRecyclerView.setLayoutManager(layoutManager);
                mAdapter = new PeopleInSpaceAdapter(mActivity, peopleInSpace);
                mRecyclerView.setHasFixedSize(true);
                mRecyclerView.setNestedScrollingEnabled(true);
                mAdapter.setDataSet(peopleInSpace);
                mRecyclerView.setAdapter(mAdapter);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError e) {
        }
    }) {

        @Override
        protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
            try {
                String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
                JSONObject jsonResponse = new JSONObject(jsonString);
                try {
                    JSONArray astronauts = jsonResponse.getJSONArray("people");
                    for (int i = 0; i < astronauts.length(); ++i) {
                        JSONObject anAstronaut = astronauts.getJSONObject(i);
                        final String name = anAstronaut.getString("name");
                        final String image = anAstronaut.getString("biophoto");
                        final String countryLink = anAstronaut.getString("countryflag");
                        final String launchDate = anAstronaut.getString("launchdate");
                        String role = anAstronaut.getString("title");
                        final String location = anAstronaut.getString("location");
                        final String bio = anAstronaut.getString("bio");
                        final String wiki = anAstronaut.getString("biolink");
                        final String twitter = anAstronaut.getString("twitter");
                        if (role != null && !role.isEmpty())
                            role = role.substring(0, 1).toUpperCase() + role.substring(1);
                        Astronaut storeAnAstronaut = new Astronaut(name, image, countryLink, launchDate, role, location, bio, wiki, twitter);
                        peopleInSpace.add(storeAnAstronaut);
                    }
                    Collections.sort(peopleInSpace);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return Response.success(new JSONObject(jsonString), HttpHeaderParser.parseCacheHeaders(response));
            } catch (UnsupportedEncodingException e) {
                return Response.error(new ParseError(e));
            } catch (JSONException je) {
                return Response.error(new ParseError(je));
            }
        }
    };
    mRequestQueue.add(jsonObjectRequest);
}
Also used : VolleyError(com.android.volley.VolleyError) Astronaut(com.restart.spacestationtracker.data.Astronaut) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JSONException(org.json.JSONException) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) PeopleInSpaceAdapter(com.restart.spacestationtracker.adapter.PeopleInSpaceAdapter) JSONException(org.json.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Response(com.android.volley.Response) NetworkResponse(com.android.volley.NetworkResponse) JSONObject(org.json.JSONObject) NetworkResponse(com.android.volley.NetworkResponse) ParseError(com.android.volley.ParseError) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 17 with Response

use of com.android.volley.Response in project easy by MehdiBenmesa.

the class StudentsListNoteAdapter method updateNotes.

public void updateNotes(Context c, String idModule) {
    StudentsListNoteAdapter.MyViewHolder child;
    final JSONArray students = new JSONArray();
    Iterator iter = myList.iterator();
    while (iter.hasNext()) {
        child = (MyViewHolder) iter.next();
        while (Float.parseFloat(child.note.getText().toString()) > 20) iter.next();
        JSONObject student = new JSONObject();
        try {
            student.put("reason", Examnote);
            student.put("value", child.note.getText().toString());
            student.put("student", child.idStudent.getText().toString());
            student.put("module", moduleid);
            students.put(student);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    CustomRequest jsonReq = new CustomRequest(Request.Method.POST, POST_NOTES, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
        //hidepDialog();
        }
    }) {

        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<String, String>();
            params.put("students", students.toString());
            return params;
        }
    };
    App.getInstance().addToRequestQueue(jsonReq);
}
Also used : VolleyError(com.android.volley.VolleyError) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) CustomRequest(dz.easy.androidclient.Util.CustomRequest) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) Iterator(java.util.Iterator)

Example 18 with Response

use of com.android.volley.Response in project easy by MehdiBenmesa.

the class AbsenceService method getAbsenceByStudentByModule.

public void getAbsenceByStudentByModule(String moduleID, final IAbsence callBack) throws JSONException {
    CustomRequestArray jsonReq = new CustomRequestArray(Request.Method.GET, GET_ABSENCE_BY_STUDENT + "/" + App.getInstance().getUser().getString("_id") + "/" + moduleID, null, new Response.Listener<JSONArray>() {

        @Override
        public void onResponse(JSONArray response) {
            callBack.onDataReceived(response);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
        }
    });
    App.getInstance().addToRequestQueue(jsonReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) CustomRequestArray(dz.easy.androidclient.Util.CustomRequestArray) JSONArray(org.json.JSONArray)

Example 19 with Response

use of com.android.volley.Response in project easy by MehdiBenmesa.

the class AbsenceService method getSeanceByTeacher.

public void getSeanceByTeacher(final IAbsence callBack) throws JSONException {
    CustomRequest jsonReq = new CustomRequest(Request.Method.GET, GET_TIME_TABLE_TEACHER + "/" + App.getInstance().getUser().getString("_id"), null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            callBack.onDataReceived(response);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
        }
    });
    App.getInstance().addToRequestQueue(jsonReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) CustomRequest(dz.easy.androidclient.Util.CustomRequest)

Example 20 with Response

use of com.android.volley.Response in project easy by MehdiBenmesa.

the class RendezVousFragment method getRendeVousByManager.

private void getRendeVousByManager() {
    CustomRequestArray jsonReq = new CustomRequestArray(Request.Method.GET, GET_RDV_BY_TEACHER, null, new Response.Listener<JSONArray>() {

        @Override
        public void onResponse(JSONArray response) {
            if (GRID_LAYOUT) {
                recyclerViewRendeVous.setLayoutManager(new GridLayoutManager(getActivity(), 2));
            } else {
                recyclerViewRendeVous.setLayoutManager(new LinearLayoutManager(getActivity()));
            }
            recyclerViewRendeVous.setHasFixedSize(true);
            //Use this now
            recyclerViewRendeVous.addItemDecoration(new MaterialViewPagerHeaderDecorator());
        //recyclerViewRendeVous.setAdapter(new TeachersAdapter(response,(TeachersAdapter.AdapterInterface) RendezVousActivity.this));
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
        }
    });
    App.getInstance().addToRequestQueue(jsonReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) CustomRequestArray(dz.easy.androidclient.Util.CustomRequestArray) GridLayoutManager(android.support.v7.widget.GridLayoutManager) JSONArray(org.json.JSONArray) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MaterialViewPagerHeaderDecorator(com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator)

Aggregations

Response (com.android.volley.Response)111 VolleyError (com.android.volley.VolleyError)109 JSONObject (org.json.JSONObject)81 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)61 RequestQueue (com.android.volley.RequestQueue)59 HashMap (java.util.HashMap)58 JSONException (org.json.JSONException)58 User (model.User)50 JSONArray (org.json.JSONArray)29 Context (android.content.Context)18 Toast (android.widget.Toast)18 CustomRequestArray (dz.easy.androidclient.Util.CustomRequestArray)18 StringRequest (com.android.volley.toolbox.StringRequest)14 TextView (android.widget.TextView)10 CustomRequest (dz.easy.androidclient.Util.CustomRequest)9 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 Intent (android.content.Intent)6 GridLayoutManager (android.support.v7.widget.GridLayoutManager)6 JsonArrayRequest (com.android.volley.toolbox.JsonArrayRequest)6 MaterialViewPagerHeaderDecorator (com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator)5