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; }
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; }
/** * 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; }
private static RequestQueue newRequestQueue() { VolleyLog.DEBUG = true; RequestQueue requestQueue = new RequestQueue(openCache(), new BasicNetwork(new HurlStack())); requestQueue.start(); CookieManager manager = new CookieManager(new SimpleCookieStore(), CookiePolicy.ACCEPT_ORIGINAL_SERVER); CookieHandler.setDefault(manager); // String userAgent = "volley/0"; // try { // String packageName = BaseApplication.getBaseApplication().getPackageName(); // PackageInfo info = BaseApplication.getBaseApplication().getPackageManager().getPackageInfo(packageName, 0); // userAgent = packageName + "/" + info.versionCode; // } catch (PackageManager.NameNotFoundException e) {} // android.net.http.AndroidHttpClient httpClient = AndroidHttpClient.newInstance(userAgent); // HttpStack httpStack = new OwnHttpClientStack(httpClient); // RequestQueue requestQueue = Volley.newRequestQueue(BaseApplication.getBaseApplication(), // httpStack); return requestQueue; }
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; }
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; }
@Override public void onCreate() { super.onCreate(); PREFS = new PreferenceWrapper( this ); PREFS.listen(); DISK_CACHE = new DiskBasedCache( getExternalCacheDir(), DISK_CACHE_SIZE ); MEMORY_CACHE = new MangaMemoryCache(); // Use the same disk cache for main and background download queues REQUEST_QUEUE = new RequestQueue( DISK_CACHE, new BasicNetwork( new HurlStack() )); REQUEST_QUEUE.start(); // Use a custom in-memory LruCache for the loader IMAGE_LOADER = new ImageLoader( REQUEST_QUEUE, MEMORY_CACHE ); // Setup databases Library.setDB( LibraryDatabaseHelper.getInstance( this ).getWritableDatabase() ); Collection.setDB( CollectionDatabaseHelper.getInstance( this ).getWritableDatabase() ); MangaUpdateReceiver.startUpdateCycle( this ); }
@Override protected void onHandleIntent(Intent intent) { // System.out.println("SEND DATA INTENT STARTED"); Connectivity connectivity = new Connectivity(this); if (!connectivity.isConnectedAndIsWifiIfOnlyWifiSet()) { DataCollectionAlarmReceiver.completeWakefulIntent(intent); ConnectivityChangeReceiver.completeWakefulIntent(intent); DataCollectionAlarmReceiver.setConnectivityChangeReceiverState(PackageManager.COMPONENT_ENABLED_STATE_ENABLED, this); // System.out.println("STOPPED SEND DATA INTENT AND ENABLED CCR - NO NETWORK"); } else { JSONPackager jsonPkgr = new JSONPackager(this); HttpPostHandler httpPostHdlr = new HttpPostHandler(this, new HurlStack()); JSONObject collectedDataJSON = jsonPkgr.createJsonObjectFromStoredData(); httpPostHdlr.postJSON(collectedDataJSON, intent); // System.out.println("SENT POST"); } }
@Override public boolean onCreate() { Context context = getContext(); if (context == null) { return false; } if (!AppPerformanceConfig.enabled) { return false; // Return when instrumentation is disabled } RequestQueue queue = new RequestQueue(new NoCache(), new BasicNetwork(new HurlStack())); queue.start(); BatteryInfoStore batteryInfoStore = new BatteryInfoStore(context); String subscriptionKey = Util.getSubscriptionKey(context); String configUrlPrefix = Util .getMeta(context, "com.rakuten.tech.mobile.perf.ConfigurationUrlPrefix"); String relayAppId = Util.getRelayAppId(context); ConfigStore configStore = new ConfigStore(context, queue, relayAppId, subscriptionKey, configUrlPrefix); // Read last config from cache Config config = createConfig(context, configStore.getObservable().getCachedValue(), relayAppId); if (config != null) { String locationUrlPrefix = Util .getMeta(context, "com.rakuten.tech.mobile.perf.LocationUrlPrefix"); LocationStore locationStore = new LocationStore(context, queue, subscriptionKey, locationUrlPrefix); // Initialise Tracking Manager TrackingManager.initialize(context, config, locationStore.getObservable(), batteryInfoStore.getObservable()); Metric.start("_launch"); } return false; }
/** * 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 } }
public RemoteDataSource(String url) { mUrl = url; // TODO: context should be Application context + this should be a singleton // mRequestQueue = Volley.newRequestQueue(context.getApplicationContext()); mRequestQueue = new RequestQueue(new NoCache(), new BasicNetwork(new HurlStack())); //TODO: disable volley cache mRequestQueue.start(); }
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(); }
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; }
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; }
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; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); requestQueue = Volley.newRequestQueue(this, new HurlStack(null, pinnedSSLSocketFactory())); }
/** * 自定义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; }
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; }
public static void setupCache(Context context){ // Instantiate the cache Cache cache = new DiskBasedCache(context.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. RequestQueue mRequestQueue; 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); }
public NetworkModelImpl() { bitmapCache = new LruBitmapCache(); Cache cache = new DiskBasedCache(App.getContext().getCacheDir(), 10 * 1024 * 1024); Network network = new BasicNetwork(new HurlStack()); requestQueue = new RequestQueue(cache, network); requestQueue.start(); }
private static RequestQueue newCustomRequestQueue(DiskBasedCache cache) { HttpStack stack = new HurlStack(); Network network = new BasicNetwork(stack); RequestQueue queue = new RequestQueue(cache, network); queue.start(); return queue; }
public RequestQueue getRequestQueue() { if (theRequestQueue == null) { // getApplicationContext() is key, it keeps you from leaking the // Activity or BroadcastReceiver if someone passes one in. theRequestQueue = Volley.newRequestQueue(thisContext.getApplicationContext(), new HurlStack(null, newSslSocketFactory())); } return theRequestQueue; }
public static void initialize(Context appContext, int lruCacheSize) { if (mGlobalRequestQueue == null) { mGlobalRequestQueue = new com.github.asifmujteba.easyvolley.ASFRequestQueue(Volley.newRequestQueue(appContext, new HurlStack(), maxDiskCacheBytes)); } if (lruCacheSize > 0) { getMemoryCache().setMaxSize(lruCacheSize); } }
public RequestQueue getRequestQueue() { if (mRequestQueue == null) { int MEGABYTE = 1024 * 1024; Cache cache = new DiskBasedCache(getCacheDir(), MEGABYTE); Network network = new BasicNetwork(new HurlStack()); mRequestQueue = new RequestQueue(cache, network); mRequestQueue.start(); } return mRequestQueue; }
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; }
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(Utils.hasHoneycomb() ? new HurlStack() : new HttpClientStack(AndroidHttpClient.newInstance(Utils.getUserAgent(context)))); Cache cache = new DiskBasedCache(getDiskCacheDir(context, CACHE_DIR), DEFAULT_DISK_USAGE_BYTES); RequestQueue queue = new RequestQueue(cache, network); queue.start(); return queue; }
private void getCategories() { final RequestQueue requestQueue = new RequestQueue(new DiskBasedCache(getCacheDir(), 0), new BasicNetwork(new HurlStack())); requestQueue.start(); JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(mTools.getApiUri()+"api/1/lvh/", new Response.Listener<JSONArray>() { @Override public void onResponse(JSONArray response) { requestQueue.stop(); mProgressBar.setVisibility(View.GONE); mSwipeRefreshLayout.setRefreshing(false); if(mTools.isTablet()) { int spanCount = (response.length() == 1) ? 1 : 2; mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL)); } mRecyclerView.setAdapter(new LvhAdapter(response)); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { requestQueue.stop(); Log.e("LvhActivity", error.toString()); } }); jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonArrayRequest); }
@Provides @Singleton public RequestQueue provideRequestQueue(@ForApplication Context context) { final int poolSize = MusicApp.isLowEndHardware(context) ? VOLLEY_POOL_SIZE_SMALL : VOLLEY_POOL_SIZE; RequestQueue queue = new RequestQueue( new DiskBasedCache(CacheUtil.getCacheDir(context, VOLLEY_CACHE_DIR), VOLLEY_CACHE_SIZE), new BasicNetwork(new HurlStack()), poolSize ); queue.start(); return queue; }
public void setUpQueue(Cache cache) { // 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(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test_main); txtDisplay = (TextView) findViewById(R.id.txtDisplay); // Instantiate the cache Cache cache = new DiskBasedCache(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(); String url = "http://172.27.9.104:9300/testdata/1/1/1/zh/CN?api=index"; JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { // TODO Auto-generated method stub txtDisplay.setText("Response => " + response.toString()); findViewById(R.id.progressBar1).setVisibility(View.GONE); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { txtDisplay.setText("VolleyError => " + error.toString()); findViewById(R.id.progressBar1).setVisibility(View.GONE); } }); mRequestQueue.add(jsObjRequest); }
/** * Initializes the image loader to its default state. This method MUST be called prior to any * further interaction with the image loader. * * @param context * The context used to create and initialize the network request queue. * @param sslSocketFactory * An optional SSL socket factory to use for the network requests. */ public synchronized void setup(Context context, SSLSocketFactory sslSocketFactory) { // Ensure the expected request queues exists. if (volleyImageRequestQueue == null) { volleyImageRequestQueue = (sslSocketFactory != null) ? Volley.newRequestQueue(context, new HurlStack(null, sslSocketFactory)) : Volley.newRequestQueue(context); volleyImageRequestQueue.start(); } // Clear out any and all queued requests. volleyImageRequestQueue.cancelAll(new RequestQueue.RequestFilter() { @Override public boolean apply(com.android.volley.Request<?> request) { return true; } }); // Clear out any cached content in the request queues. Cache requestCache = volleyImageRequestQueue.getCache(); if (requestCache != null) { requestCache.clear(); } // Ensure the expected image cache exists. if (imageCache == null) { DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); int width = displayMetrics.widthPixels; int height = displayMetrics.heightPixels; int maxSizeKb = width * height * 4 * 3 / 1024; // * 4 = magic unicorn, * 3 = 3 full screens worth of memory imageCache = new ImageCache(maxSizeKb); } // Clear out any and all cached images. imageCache.evictAll(); if (imageLoader == null) { imageLoader = new com.android.volley.toolbox.ImageLoader(volleyImageRequestQueue, imageCache); } }
private HurlStack getHurlStack() { SSLSocketFactory sslSocketFactory = getSSLSocketFactory(); if (sslSocketFactory != null) { return new HurlStack(null, sslSocketFactory); } return new HurlStack(); }
public static HttpStack createStack() { if(hasOkHttp()) { OkHttpClient okHttpClient = new OkHttpClient(); VolleyLog.d("OkHttp found, using okhttp for http stack"); return new OkHttpStack(okHttpClient); } else if (useHttpClient()){ VolleyLog.d("Android version is older than Gingerbread (API 9), using HttpClient"); return new HttpClientStack(AndroidHttpClient.newInstance(USER_AGENT)); } else { VolleyLog.d("Using Default HttpUrlConnection"); return new HurlStack(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); firstTimeSettings(); setContentView(R.layout.activity_main_screen); mSendDataProgressBar = (ProgressBar) findViewById(R.id.main_screen_send_data_progress_bar); mSendDataProgressBar.setVisibility(View.INVISIBLE); mJSONPackager = new JSONPackager(getApplicationContext()); mHttpPOSTHandler = new HttpPostHandler(getApplicationContext(), new HurlStack()); mHttpPOSTHandler.setMainScreen(this); }
private RequestQueue createRequestQueue(Context context) { if (context == null) { return null; } File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); Network network = new BasicNetwork(new HurlStack()); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir, DEFAULT_CACHE_SIZE), network); queue.start(); return queue; }
/** * Creates a default instance of the worker pool and calls RequestQueue.start() on it. * * @return A started RequestQueue instance. */ private RequestQueue getRequestQueue() { if (mRequestQueue == null) mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext(), new HurlStack()); return mRequestQueue; }
public RemoteDataSource(String url) { mUrl = url; mRequestQueue = new RequestQueue(new NoCache(), new BasicNetwork(new HurlStack())); mRequestQueue.start(); }