Java 类com.android.volley.Network 实例源码

项目:CursoAndroid    文件:ApiClient.java   
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {

        // Instantiate the cache
        Cache cache = new DiskBasedCache(mContext.getCacheDir(), 1024 * 1024); // 1MB cap
        // 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();

        // getApplicationContext() is key, it keeps you from leaking the
        // Activity or BroadcastReceiver if someone passes one in.
        //mRequestQueue = Volley.newRequestQueue(mContext.getApplicationContext());
    }
    return mRequestQueue;
}
项目:Goalie_Android    文件:BaseTest.java   
private RequestQueue newVolleyRequestQueueForTest(final Context context) {
    File cacheDir = new File(context.getCacheDir(), "cache/volley");
    Network network = new BasicNetwork(new HurlStack());
    ResponseDelivery responseDelivery = new ExecutorDelivery(Executors.newSingleThreadExecutor());
    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network, 4, responseDelivery);
    queue.start();

    return queue;
}
项目:AyoSunny    文件:Volley.java   
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 * You may set a maximum size of the disk cache in bytes.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @param maxDiskCacheBytes the maximum size of the disk cache, in bytes. Use -1 for default size.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack, int maxDiskCacheBytes) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    if (stack == null) {
        stack = new HurlStack();
    }
    Network network = new BasicNetwork(stack);//Build.VERSION.SDK_INT >= 9

    RequestQueue queue;
    if (maxDiskCacheBytes <= -1)
    {
        // No maximum size specified
        queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    }
    else
    {
        // Disk cache size specified
        queue = new RequestQueue(new DiskBasedCache(cacheDir, maxDiskCacheBytes), network);
    }

    queue.start();

    return queue;
}
项目:SaveVolley    文件:RequestQueueTest.java   
@Test public void publicMethods() throws Exception {
    // Catch-all test to find API-breaking changes.
    assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class,
            ResponseDelivery.class));
    assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class));
    assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class));

    assertNotNull(RequestQueue.class.getMethod("start"));
    assertNotNull(RequestQueue.class.getMethod("stop"));
    assertNotNull(RequestQueue.class.getMethod("getSequenceNumber"));
    assertNotNull(RequestQueue.class.getMethod("getCache"));
    assertNotNull(RequestQueue.class.getMethod("cancelAll", RequestQueue.RequestFilter.class));
    assertNotNull(RequestQueue.class.getMethod("cancelAll", Object.class));
    assertNotNull(RequestQueue.class.getMethod("add", Request.class));
    assertNotNull(RequestQueue.class.getDeclaredMethod("finish", Request.class));
}
项目:shutterstock-image-browser    文件:VolleySingleton.java   
/**
 * Creates a new Request Queue which caches to the external storage directory
 * @param context
 * @return
 */
private static RequestQueue newRequestQueue(Context context) {
    // define cache folder
    File rootCache = context.getExternalCacheDir();
    if (rootCache == null) {
        Log.w(TAG, "Can't find External Cache Dir, "
                + "switching to application specific cache directory");
        rootCache = context.getCacheDir();
    }

    File cacheDir = new File(rootCache, DEFAULT_CACHE_DIR);
    cacheDir.mkdirs();

    HttpStack stack = new HurlStack();
    Network network = new BasicNetwork(stack);
    DiskBasedCache diskBasedCache = new DiskBasedCache(cacheDir, DEFAULT_DISK_USAGE_BYTES);
    RequestQueue queue = new RequestQueue(diskBasedCache, network);
    queue.start();

    return queue;
}
项目:android-project-template    文件:DrupalModel.java   
/**
 * volley's default implementation uses internal cache only so we've implemented our, allowing
 * external cache usage.
 */
@NonNull
private static RequestQueue newRequestQueue(@NonNull final Context context,
        @Nullable HttpStack stack) {

    final VolleyHelperFactory.IVolleyHelper helper = VolleyHelperFactory.newHelper();
    final File cacheDir = helper.getBestCacheDir(context);

    if (stack == null) {
        stack = helper.createHttpStack(context);
    }

    final Network network = new BasicNetwork(stack);
    final RequestQueue queue = new RequestQueue(
            new DiskBasedCache(cacheDir, ApplicationConfig.CACHE_DISK_USAGE_BYTES), network, 1);
    queue.start();
    return queue;
}
项目:android-project-template    文件:Model.java   
/**
 * volley's default implementation uses internal cache only so we've implemented our, allowing
 * external cache usage.
 */
private static RequestQueue newRequestQueue(@NonNull final Context context,
        @Nullable HttpStack stack) {

    final VolleyHelperFactory.IVolleyHelper helper = VolleyHelperFactory.newHelper();
    final File cacheDir = helper.getBestCacheDir(context);

    if (stack == null) {
        stack = helper.createHttpStack(context);
    }

    final Network network = new BasicNetwork(stack);
    final RequestQueue queue = new RequestQueue(
            new DiskBasedCache(cacheDir, ApplicationConfig.CACHE_DISK_USAGE_BYTES), network, 1);
    queue.start();
    return queue;
}
项目:Wardrobe_app    文件:ImageLoader.java   
private static RequestQueue newRequestQueue(Context context) {

        // On HC+ use HurlStack which is based on HttpURLConnection. Otherwise fall back on
        // AndroidHttpClient (based on Apache DefaultHttpClient) which should no longer be used
        // on newer platform versions where HttpURLConnection is simply better.
        Network network = new BasicNetwork(
                UIUtils.hasHoneycomb() ?
                        new HurlStack() :
                        new HttpClientStack(AndroidHttpClient.newInstance(
                                NetUtils.getUserAgent(context))));

        Cache cache = new DiskBasedCache(getDiskCacheDir(context, CACHE_DIR));
        RequestQueue queue = new RequestQueue(cache, network);
        queue.start();
        return queue;
    }
项目:io2014-codelabs    文件:CloudBackendFragment.java   
private RequestQueue newRequestQueue(Context context) {
    // define cache folder
    File rootCache = context.getExternalCacheDir();
    if (rootCache == null) {
        rootCache = context.getCacheDir();
    }

    File cacheDir = new File(rootCache, DEFAULT_CACHE_DIR);
    cacheDir.mkdirs();

    HttpStack stack = new HurlStack();
    Network network = new BasicNetwork(stack);
    DiskBasedCache diskBasedCache = new DiskBasedCache(cacheDir, DEFAULT_DISK_USAGE_BYTES);
    RequestQueue queue = new RequestQueue(diskBasedCache, network);
    queue.start();

    return queue;
}
项目:CrossBow    文件:Crossbow.java   
public Crossbow(Context context, CrossbowComponents crossbowComponents) {
    this.context = context.getApplicationContext();
    this.requestQueue = crossbowComponents.provideRequestQueue();
    this.imageLoader = crossbowComponents.provideImageLoader();
    this.imageCache = crossbowComponents.provideImageCache();

    Cache cache = crossbowComponents.provideCache();
    Network network = crossbowComponents.provideNetwork();

    FileDelivery fileDelivery = new BasicFileDelivery();
    FileStack fileStack = new BasicFileStack(context);
    fileQueue = new FileQueue(fileDelivery, fileStack);
    fileQueue.start();
    fileImageLoader = new FileImageLoader(fileQueue, imageCache);

    syncDispatcher = new SyncDispatcher(cache, network);
}
项目:iosched2013    文件:ImageLoader.java   
private static RequestQueue newRequestQueue(Context context) {

        // On HC+ use HurlStack which is based on HttpURLConnection. Otherwise fall back on
        // AndroidHttpClient (based on Apache DefaultHttpClient) which should no longer be used
        // on newer platform versions where HttpURLConnection is simply better.
        Network network = new BasicNetwork(
                UIUtils.hasHoneycomb() ?
                        new HurlStack() :
                        new HttpClientStack(AndroidHttpClient.newInstance(
                                NetUtils.getUserAgent(context))));

        Cache cache = new DiskBasedCache(getDiskCacheDir(context, CACHE_DIR));
        RequestQueue queue = new RequestQueue(cache, network);
        queue.start();
        return queue;
    }
项目:Qmusic    文件:QMusicRequestManager.java   
/**
 * Use a custom L2 cache,support LRU
 * 
 * @param context
 * @param uniqueName
 * @param diskCacheSize
 * @param memCacheSize
 * @param compressFormat
 * @param quality
 * @param type
 */
private QMusicRequestManager(final Context context, final int diskCacheSize, final int memCacheSize) {
    // ============L2 Cache=============
    HttpStack stack = getHttpStack(false);
    Network network = new BasicNetwork(stack);
    if (L2CacheType == 0) {
        // TODO: this L2 cache implement ignores the HTTP cache headers
        mCacheL2 = new VolleyL2DiskLruCache(new File(context.getCacheDir(), "L2-Cache"), diskCacheSize);
    } else {
        // The build-in L2 cache has no LRU
        mCacheL2 = new DiskBasedCache(new File(context.getCacheDir(), "L2-Cache"), diskCacheSize);
    }
    mRequestQueue = new RequestQueue(mCacheL2, network);
    mRequestQueue.start();
    // ============L1 Cache=============
    if (L1CacheType == 0) {
        mCacheL1 = new VolleyL1MemoryLruImageCache(memCacheSize);
    } else {
        mCacheL1 = new VolleyL1DiskLruImageCache(context, "L1-Cache", diskCacheSize, CompressFormat.JPEG, 80);
    }
    mImageLoader = new ImageLoader(mRequestQueue, mCacheL1);
}
项目:GitHub    文件:Volley.java   
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
项目:payments-Android-SDK    文件:ApiInvoker.java   
public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) {
  INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout);
  setUserAgent("Swagger-Codegen/1.0.0/android");

  // Setup authentications (key: authentication name, value: authentication).
  INSTANCE.authentications = new HashMap<String, Authentication>();
  // Prevent the authentications from being modified.
  INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications);
}
项目:Codeforces    文件:Volley.java   
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
项目:iosched-reader    文件:Volley.java   
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
项目:plainrequest    文件:PlainRequestQueue.java   
/**
 * Inicia uma instancia da lib PlainRequest
 * utilizando cache do volley
 *
 * @param app
 * @param sizeCache // tamanho do cache em MB
 */
public void start(Application app, int sizeCache) {
    if(context == null) {
        context = app.getApplicationContext();
        // Cache
        Cache cache = new DiskBasedCache(app.getCacheDir(), (1024 * 1024) * sizeCache);
        Network network = new BasicNetwork(new HurlStack());
        queue = new RequestQueue(cache, network); // Criação do RequestQueue
    }
}
项目:swaggy-jenkins    文件:ApiInvoker.java   
public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) {
  INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout);
  setUserAgent("Swagger-Codegen/1.0.0/android");

  // Setup authentications (key: authentication name, value: authentication).
  INSTANCE.authentications = new HashMap<String, Authentication>();
  INSTANCE.authentications.put("jenkins_auth", new HttpBasicAuth());
  // Prevent the authentications from being modified.
  INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications);
}
项目:malp    文件:HTTPAlbumImageProvider.java   
private HTTPAlbumImageProvider(Context context) {
    // Don't use MALPRequestQueue because we do not need to limit the load on the local server
    Network network = new BasicNetwork(new HurlStack());
    // 10MB disk cache
    Cache cache = new DiskBasedCache(context.getCacheDir(), 1024 * 1024 * 10);

    mRequestQueue = new RequestQueue(cache, network);
    mRequestQueue.start();
}
项目:malp    文件:MALPRequestQueue.java   
private MALPRequestQueue(Cache cache, Network network) {
    super(cache, network, 1);
    mCache = cache;
    mNetwork = network;
    mLimitingRequestQueue = new LinkedBlockingQueue<>();
    mLimiterTimer = null;
    super.addRequestFinishedListener(this);
}
项目:malp    文件:MALPRequestQueue.java   
public synchronized static 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;
}
项目:NetRequest    文件:VolleyManagerNew.java   
private void initRequestQueue(@NonNull Context context) {
    if (mRequestQueue != null) {
        return;
    }
    Network network = new BasicNetwork(new OkHttpStack());
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
    mRequestQueue = new RequestQueue(new DiskBasedCache(cacheDir), network, DEFAULT_NETWORK_THREAD_POOL_SIZE);
    mRequestQueue.start();
}
项目:NetRequest    文件:VolleyManager.java   
private void initRequestQueue(@NonNull Context context) {
    if (mRequestQueue != null) {
        return;
    }
    Network network = new BasicNetwork(new OkHttpStack());
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
    mRequestQueue = new RequestQueue(new DiskBasedCache(cacheDir), network, DEFAULT_NETWORK_THREAD_POOL_SIZE);
    mRequestQueue.start();
}
项目:VoV    文件:Volley.java   
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
项目:smconf-android    文件:Volley.java   
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
项目:volley    文件:Volley.java   
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
项目:MeifuGO    文件:Volley.java   
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "com/android/volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
项目:VolleyImageLoader    文件:CustomVolleyRequestQueue.java   
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        Cache cache = new DiskBasedCache(mCtx.getCacheDir(), 10 * 1024 * 1024);
        Network network = new BasicNetwork(new HurlStack());
        mRequestQueue = new RequestQueue(cache, network);
        // Don't forget to start the volley request queue
        mRequestQueue.start();
    }
    return mRequestQueue;
}
项目:VolleyBecomesEasy    文件:CustomVolleyRequestQueue.java   
public RequestQueue getRequestQueue() {
    if (requestQueue == null) {
        Cache cache = new DiskBasedCache(ctx.getCacheDir(), 10 * 1024 * 1024);
        Network network = new BasicNetwork(new HurlStack());
        requestQueue = new RequestQueue(cache, network);
        // Don't forget to start the volley request queue
        requestQueue.start();
    }
    return requestQueue;
}
项目:InfoQ-Android-App    文件:Volley.java   
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
项目:VolleyExample    文件:CustomVolleyRequestQueue.java   
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        Cache cache = new DiskBasedCache(mCtx.getCacheDir(), 10 * 1024 * 1024);
        Network network = new BasicNetwork(new HurlStack());
        mRequestQueue = new RequestQueue(cache, network);
        // Don't forget to start the volley request queue
        mRequestQueue.start();
    }
    return mRequestQueue;
}
项目:volley-public-key-pinning    文件:Volley.java   
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
项目:HappyVolley    文件:HappyRequestQueue.java   
/**
 * 自定义Volley请求Queue
 *
 * @param context Context
 * @return RequestQueue
 */
public RequestQueue newRequestQueue(Context context) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
    Network network = new BasicNetwork(new HurlStack());
    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir),
            network,
            DEFAULT_NETWORK_THREAD_POOL_SIZE,
            new ExecutorDelivery(executorService));
    queue.start();
    return queue;
}
项目:device-database    文件:Volley.java   
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
项目:Airbnb-Android-Google-Map-View    文件:CustomVolleyRequestQueue.java   
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        Cache cache = new DiskBasedCache(mCtx.getCacheDir(), 10 * 1024 * 1024);
        Network network = new BasicNetwork(new HurlStack());
        mRequestQueue = new RequestQueue(cache, network);
        // Don't forget to start the volley request queue
        mRequestQueue.start();
    }
    return mRequestQueue;
}
项目:ShoppingApp    文件:Volley.java   
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
项目:ef-app_android    文件:ApiInvoker.java   
public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) {
   INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout);
   setUserAgent("Swagger-Codegen/1.0.0/android");

   // Setup authentications (key: authentication name, value: authentication).
   INSTANCE.authentications = new HashMap<String, Authentication>();
   INSTANCE.authentications.put("Bearer", new ApiKeyAuth("header", "Authorization"));
   // Prevent the authentications from being modified.
   INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications);
}
项目:odyssey    文件:LimitingRequestQueue.java   
private LimitingRequestQueue(Cache cache, Network network) {
    super(cache, network, 1);
    mCache = cache;
    mNetwork = network;
    mLimitingRequestQueue = new LinkedBlockingQueue<>();
    mLimiterTimer = null;
    super.addRequestFinishedListener(this);
}
项目:odyssey    文件:LimitingRequestQueue.java   
public synchronized static LimitingRequestQueue 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 LimitingRequestQueue(cache,network);
        mInstance.start();
    }
    return mInstance;
}
项目:2015-Google-I-O-app    文件:Volley.java   
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}