Search in sources :

Example 26 with VolleyError

use of com.android.volley.VolleyError in project WordPress-Android by wordpress-mobile.

the class WPImageGetter method getDrawable.

@Override
public Drawable getDrawable(String source) {
    if (mImageLoader == null || mLoadingDrawable == null || mFailedDrawable == null) {
        throw new RuntimeException("Developer, you need to call setImageLoader, setLoadingDrawable and setFailedDrawable");
    }
    if (TextUtils.isEmpty(source)) {
        return null;
    }
    // images in reader comments may skip "http:" (no idea why) so make sure to add protocol here
    if (source.startsWith("//")) {
        source = "http:" + source;
    }
    // and then resized)
    if (mMaxSize > 0) {
        source = PhotonUtils.getPhotonImageUrl(source, mMaxSize, 0);
    }
    final RemoteDrawable remote = new RemoteDrawable(mLoadingDrawable, mFailedDrawable);
    mImageLoader.get(source, new ImageLoader.ImageListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            remote.displayFailed();
            TextView view = getView();
            if (view != null) {
                view.invalidate();
            }
        }

        @Override
        public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
            if (response.getBitmap() == null) {
                AppLog.w(T.UTILS, "WPImageGetter null bitmap");
            }
            TextView view = getView();
            if (view == null) {
                AppLog.w(T.UTILS, "WPImageGetter view is invalid");
                return;
            }
            int maxWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
            if (mMaxSize > 0 && (maxWidth > mMaxSize || maxWidth == 0)) {
                maxWidth = mMaxSize;
            }
            Drawable drawable = new BitmapDrawable(view.getContext().getResources(), response.getBitmap());
            remote.setRemoteDrawable(drawable, maxWidth);
            // accommodate the image isn't necessary
            if (!isImmediate) {
                view.setText(view.getText());
            }
        }
    });
    return remote;
}
Also used : VolleyError(com.android.volley.VolleyError) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) TextView(android.widget.TextView) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageLoader(com.android.volley.toolbox.ImageLoader)

Example 27 with VolleyError

use of com.android.volley.VolleyError 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)

Example 28 with VolleyError

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

the class RendezVousFragment method accept.

public void accept(JSONObject rdv, final String date, final String heur, final String remarque) {
    CustomRequest jsonReq = null;
    try {
        jsonReq = new CustomRequest(Request.Method.POST, ACCEPT_RDV + "/" + rdv.getString("_id"), 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("date", date);
                params.put("heur", heur);
                params.put("remarque", remarque);
                return params;
            }
        };
    } catch (JSONException e) {
        e.printStackTrace();
    }
    App.getInstance().addToRequestQueue(jsonReq);
}
Also used : VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) CustomRequest(dz.easy.androidclient.Util.CustomRequest) Map(java.util.Map) HashMap(java.util.HashMap)

Example 29 with VolleyError

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

the class RendezVousService method getRendezVousByTeacher.

private void getRendezVousByTeacher(String rdvState, final IRendezVous callBack) throws JSONException {
    CustomRequestArray jsonReq = new CustomRequestArray(Request.Method.GET, GET_RDV_BY_TEACHER + "/" + rdvState + "/" + App.getInstance().getUser().getString("_id"), null, new Response.Listener<JSONArray>() {

        @Override
        public void onResponse(JSONArray response) {
            callBack.onDataRecieved(response);
        //   recyclerViewRendeVous.setAdapter(new TestRecyclerViewAdapter(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 30 with VolleyError

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

the class RendezVousService method getRendeVousByStudent.

private void getRendeVousByStudent(String rdvState, final IRendezVous callBack) throws JSONException {
    CustomRequestArray jsonReq = new CustomRequestArray(Request.Method.GET, GET_RDV_BY_STUDENT + "/" + rdvState + "/" + App.getInstance().getUser().getString("_id"), null, new Response.Listener<JSONArray>() {

        @Override
        public void onResponse(JSONArray response) {
            callBack.onDataRecieved(response);
        //  recyclerViewRendeVous.setAdapter(new TestRecyclerViewAdapter(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)

Aggregations

VolleyError (com.android.volley.VolleyError)180 Response (com.android.volley.Response)121 JSONObject (org.json.JSONObject)104 HashMap (java.util.HashMap)70 JSONException (org.json.JSONException)66 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)61 RequestQueue (com.android.volley.RequestQueue)57 User (model.User)49 JSONArray (org.json.JSONArray)35 CustomRequestArray (dz.easy.androidclient.Util.CustomRequestArray)18 Context (android.content.Context)16 Toast (android.widget.Toast)16 StringRequest (com.android.volley.toolbox.StringRequest)16 RestRequest (com.wordpress.rest.RestRequest)16 CustomRequest (dz.easy.androidclient.Util.CustomRequest)12 TextView (android.widget.TextView)11 MockHttpStack (com.android.volley.mock.MockHttpStack)9 GsonRequest (com.android.volley.toolbox.GsonRequest)9 ImageContainer (com.android.volley.toolbox.ImageLoader.ImageContainer)9 Test (org.junit.Test)9