Search in sources :

Example 1 with DiskBasedCache

use of com.android.volley.toolbox.DiskBasedCache in project BestPracticeApp by pop1234o.

the class MainActivity method requestVolley2.

/**
 * 自己配置请求client
 */
private void requestVolley2() {
    RequestQueue mRequestQueue;
    // Instantiate the cache
    // 1MB cap
    Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024);
    // Set up the network to use HttpURLConnection as the HTTP client.
    Network network = new BasicNetwork(new HurlStack());
    // Instantiate the RequestQueue with the cache and network.
    mRequestQueue = new RequestQueue(cache, network);
    // Start the queue
    mRequestQueue.start();
    String url = "http://www.example.com";
    // Formulate the request and handle the response.
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
        // Do something with the response
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
        // Handle error
        }
    });
    // Add the request to the RequestQueue.
    mRequestQueue.add(stringRequest);
}
Also used : VolleyError(com.android.volley.VolleyError) HurlStack(com.android.volley.toolbox.HurlStack) StringRequest(com.android.volley.toolbox.StringRequest) DiskBasedCache(com.android.volley.toolbox.DiskBasedCache) Response(com.android.volley.Response) BasicNetwork(com.android.volley.toolbox.BasicNetwork) RequestQueue(com.android.volley.RequestQueue) Network(com.android.volley.Network) BasicNetwork(com.android.volley.toolbox.BasicNetwork) Cache(com.android.volley.Cache) DiskBasedCache(com.android.volley.toolbox.DiskBasedCache)

Example 2 with DiskBasedCache

use of com.android.volley.toolbox.DiskBasedCache in project fresco by facebook.

the class SampleVolleyFactory method getRequestQueue.

public static RequestQueue getRequestQueue(Context context) {
    if (sRequestQueue == null) {
        File cacheDir = new File(context.getCacheDir(), VOLLEY_CACHE_DIR);
        sRequestQueue = new RequestQueue(new DiskBasedCache(cacheDir, ConfigConstants.MAX_DISK_CACHE_SIZE), new BasicNetwork(new HurlStack()));
        sRequestQueue.start();
    }
    return sRequestQueue;
}
Also used : BasicNetwork(com.android.volley.toolbox.BasicNetwork) HurlStack(com.android.volley.toolbox.HurlStack) RequestQueue(com.android.volley.RequestQueue) DiskBasedCache(com.android.volley.toolbox.DiskBasedCache) File(java.io.File)

Example 3 with DiskBasedCache

use of com.android.volley.toolbox.DiskBasedCache in project OkVolley by googolmo.

the class OkVolley method newRequestQueue.

public static RequestQueue newRequestQueue(Context context) {
    if (InstanceNetwork == null) {
        InstanceNetwork = new OkNetwork(getDefaultHttpStack());
    }
    if (InstanceCache == null) {
        File cache = context.getExternalCacheDir();
        if (cache == null) {
            cache = context.getCacheDir();
        }
        File cacheDir = new File(cache, DEFAULT_CACHE_DIR);
        InstanceCache = new DiskBasedCache(cacheDir);
    }
    RequestQueue queue = new RequestQueue(InstanceCache, InstanceNetwork);
    queue.start();
    return queue;
}
Also used : RequestQueue(com.android.volley.RequestQueue) OkNetwork(im.amomo.volley.OkNetwork) DiskBasedCache(com.android.volley.toolbox.DiskBasedCache) File(java.io.File)

Example 4 with DiskBasedCache

use of com.android.volley.toolbox.DiskBasedCache in project Douya by DreaminginCodeZH.

the class Volley method createAndStartRequestQueue.

/**
     * @see com.android.volley.toolbox.Volley#newRequestQueue(Context, HttpStack)
     */
private void createAndStartRequestQueue() {
    mRequestQueue = new RequestQueue(new DiskBasedCache(new File(DouyaApplication.getInstance().getCacheDir(), "volley")), new BasicNetwork(new HurlStack()));
    mRequestQueue.start();
}
Also used : RequestQueue(com.android.volley.RequestQueue) DiskBasedCache(com.android.volley.toolbox.DiskBasedCache) File(java.io.File)

Example 5 with DiskBasedCache

use of com.android.volley.toolbox.DiskBasedCache in project malp by gateship-one.

the class MALPRequestQueue method getInstance.

public static synchronized MALPRequestQueue getInstance(Context context) {
    if (null == mInstance) {
        Network network = new BasicNetwork(new HurlStack());
        // 10MB disk cache
        Cache cache = new DiskBasedCache(context.getCacheDir(), 1024 * 1024 * 10);
        mInstance = new MALPRequestQueue(cache, network);
        mInstance.start();
    }
    return mInstance;
}
Also used : BasicNetwork(com.android.volley.toolbox.BasicNetwork) HurlStack(com.android.volley.toolbox.HurlStack) Network(com.android.volley.Network) BasicNetwork(com.android.volley.toolbox.BasicNetwork) DiskBasedCache(com.android.volley.toolbox.DiskBasedCache) Cache(com.android.volley.Cache) DiskBasedCache(com.android.volley.toolbox.DiskBasedCache)

Aggregations

DiskBasedCache (com.android.volley.toolbox.DiskBasedCache)6 RequestQueue (com.android.volley.RequestQueue)5 BasicNetwork (com.android.volley.toolbox.BasicNetwork)4 HurlStack (com.android.volley.toolbox.HurlStack)4 Cache (com.android.volley.Cache)3 Network (com.android.volley.Network)3 File (java.io.File)3 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1 StringRequest (com.android.volley.toolbox.StringRequest)1 OkNetwork (im.amomo.volley.OkNetwork)1