Back to project page Android_Yellow_Pages_App_Content_Provider.
The source code is released under:
Apache License
If you think the Android project Android_Yellow_Pages_App_Content_Provider listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.tddrampup.serviceLayers; // w ww. j av a 2s.c om import android.content.Context; import android.util.Log; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.JsonObjectRequest; import com.android.volley.toolbox.Volley; import com.google.gson.Gson; import com.tddrampup.fragments.ListFragment; import com.tddrampup.models.Listing; import com.tddrampup.models.YellowResponse; import org.json.JSONObject; /** * Created by WX009-PC on 2/20/14. */ public class VolleyServiceLayer { private final RequestQueue mRequestQueue; public VolleyServiceLayerCallback volleyServiceLayerCallback; public VolleyServiceLayer(Context context){ mRequestQueue = Volley.newRequestQueue(context); } public void GetListings(String url) { JsonObjectRequest jr = new JsonObjectRequest(Request.Method.GET,url,null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Gson gson = new Gson(); YellowResponse yellowResponse = gson.fromJson(response.toString(), YellowResponse.class); volleyServiceLayerCallback.listCallbackCall(yellowResponse.getListings()); } },new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d("LOGGING:", error.getMessage()); } }); mRequestQueue.add(jr); } public void GetListing(String id, final Boolean isSearchQuery) { String url ="http://api.sandbox.yellowapi.com/GetBusinessDetails/?listingId="+ id +"&bus-name=Yellow-Pages-Group&city=Toronto&prov=Ontario&fmt=JSON&lang=en&UID=fgdfg&apikey=" + ListFragment.API_KEY; JsonObjectRequest jr = new JsonObjectRequest(Request.Method.GET,url,null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Gson gson = new Gson(); Listing listing = gson.fromJson(response.toString(), Listing.class); volleyServiceLayerCallback.itemCallbackCall(listing, isSearchQuery); } },new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d("LOGGING:", error.getMessage()); } }); mRequestQueue.add(jr); } }