當前位置: 首頁>>代碼示例>>Java>>正文


Java Network類代碼示例

本文整理匯總了Java中com.android.volley.Network的典型用法代碼示例。如果您正苦於以下問題:Java Network類的具體用法?Java Network怎麽用?Java Network使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Network類屬於com.android.volley包,在下文中一共展示了Network類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRequestQueue

import com.android.volley.Network; //導入依賴的package包/類
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;
}
 
開發者ID:delizondo,項目名稱:CursoAndroid,代碼行數:19,代碼來源:ApiClient.java

示例2: newVolleyRequestQueueForTest

import com.android.volley.Network; //導入依賴的package包/類
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;
}
 
開發者ID:Q115,項目名稱:Goalie_Android,代碼行數:10,代碼來源:BaseTest.java

示例3: newRequestQueue

import com.android.volley.Network; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:cowthan,項目名稱:AyoSunny,代碼行數:34,代碼來源:Volley.java

示例4: publicMethods

import com.android.volley.Network; //導入依賴的package包/類
@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));
}
 
開發者ID:CaMnter,項目名稱:SaveVolley,代碼行數:17,代碼來源:RequestQueueTest.java

示例5: newRequestQueue

import com.android.volley.Network; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:bilbo7833,項目名稱:shutterstock-image-browser,代碼行數:26,代碼來源:VolleySingleton.java

示例6: newRequestQueue

import com.android.volley.Network; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:lemberg,項目名稱:android-project-template,代碼行數:22,代碼來源:DrupalModel.java

示例7: newRequestQueue

import com.android.volley.Network; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:lemberg,項目名稱:android-project-template,代碼行數:21,代碼來源:Model.java

示例8: newRequestQueue

import com.android.volley.Network; //導入依賴的package包/類
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;
    }
 
開發者ID:BitCypher2014,項目名稱:Wardrobe_app,代碼行數:17,代碼來源:ImageLoader.java

示例9: newRequestQueue

import com.android.volley.Network; //導入依賴的package包/類
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;
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:19,代碼來源:CloudBackendFragment.java

示例10: Crossbow

import com.android.volley.Network; //導入依賴的package包/類
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);
}
 
開發者ID:patrick-doyle,項目名稱:CrossBow,代碼行數:18,代碼來源:Crossbow.java

示例11: QMusicRequestManager

import com.android.volley.Network; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:qianweicheng,項目名稱:Qmusic,代碼行數:33,代碼來源:QMusicRequestManager.java

示例12: newRequestQueue

import com.android.volley.Network; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:36,代碼來源:Volley.java

示例13: initializeInstance

import com.android.volley.Network; //導入依賴的package包/類
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);
}
 
開發者ID:wondenge,項目名稱:payments-Android-SDK,代碼行數:10,代碼來源:ApiInvoker.java

示例14: start

import com.android.volley.Network; //導入依賴的package包/類
/**
 * 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
    }
}
 
開發者ID:giovanimoura,項目名稱:plainrequest,代碼行數:17,代碼來源:PlainRequestQueue.java

示例15: initializeInstance

import com.android.volley.Network; //導入依賴的package包/類
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);
}
 
開發者ID:cliffano,項目名稱:swaggy-jenkins,代碼行數:11,代碼來源:ApiInvoker.java


注:本文中的com.android.volley.Network類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。