@Override protected void onStop() { HttpResponseCache cache = HttpResponseCache.getInstalled(); if (cache != null) { cache.flush(); } super.onStop(); }
static Object install(Context context) throws IOException { File cacheDir = Utils.createDefaultCacheDir(context); HttpResponseCache cache = HttpResponseCache.getInstalled(); if (cache == null) { int maxSize = Utils.calculateDiskCacheSize(cacheDir); cache = HttpResponseCache.install(cacheDir, maxSize); } return cache; }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override protected void onStop() { super.onStop(); HttpResponseCache cache = HttpResponseCache.getInstalled(); if (cache != null) { cache.flush(); } }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_lista); try { File httpCacheDir = new File(getApplicationContext().getCacheDir(), "http"); long httpCacheSize = 10 * 1024 * 1024; // 10 MiB HttpResponseCache.install(httpCacheDir, httpCacheSize); } catch (IOException e) { Log.i("TAG", "HTTP response cache installation failed:" + e); } produtosBD = new ArrayList<>(); lista = (ListView) findViewById(R.id.listView); autoComplete = (AutoCompleteTextView) findViewById(R.id.autoComplete); baseProgressBar = (LinearLayout) findViewById(R.id.baseProgressBar); ctx = this; minhaLista = new ArrayList<>(); bundle = getIntent().getExtras(); new GetListaWS().execute(); }
@Override public void close() throws IOException { if (ResponseCache.getDefault() == this.delegate) { ResponseCache.setDefault(null); } delegate.close(); }
/* * enable caching for HttpUrlConnection * http://developer.android.com/training/efficient-downloads/redundant_redundant.html */ private static void enableHttpResponseCache(Context context) { try { long httpCacheSize = 5 * 1024 * 1024; // 5MB File httpCacheDir = new File(context.getCacheDir(), "http"); HttpResponseCache.install(httpCacheDir, httpCacheSize); } catch (IOException e) { AppLog.w(T.UTILS, "Failed to enable http response cache"); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { File httpCacheDir = new File(getCacheDir(), "http"); long httpCacheSize = 10 * 1024 * 1024; // 10 MiB HttpResponseCache.install(httpCacheDir, httpCacheSize); } catch (IOException e) { Log.i(TAG, "HTTP response cache installation failed:" + e); } dh1 = (Button) findViewById(R.id.dh1); dh2 = (Button) findViewById(R.id.dh2); about = (Button) findViewById(R.id.about); dh1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { flg = 0; if (isConnected()) { new fetchMenu().execute("dh1"); } else { Toast.makeText( getApplicationContext(), getString(R.string.NoInternet), Toast.LENGTH_LONG) .show(); } } }); dh2.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { flg = 1; if (isConnected()) { new fetchMenu().execute("dh2"); } else { Toast.makeText( getApplicationContext(), getString(R.string.NoInternet), Toast.LENGTH_LONG) .show(); } } }); about.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent in = new Intent(MainActivity.this, info.class); startActivity(in); } }); }
private void installHtppCache() { try { File dir = getCacheDir(); File httpCacheDir = new File(dir, "logoCache"); long httpCacheSize = 10 * 1024 * 1024; // 10 MiB HttpResponseCache.install(httpCacheDir, httpCacheSize); } catch (IOException e) { Log.i(getClass().getSimpleName(), "HTTP response cache installation failed:" + e); } }
public static HttpResponseCache install(Context context) throws IOException { ResponseCache installed = ResponseCache.getDefault(); if (installed instanceof Closeable) { ((Closeable) installed).close(); } File directory = SystemUtils.getCacheDir(context, "http"); long maxSize = SystemUtils.calculateDiskCacheSize(directory, MIN_DISK_CACHE_SIZE, MAX_DISK_CACHE_SIZE); return new HttpResponseCache(android.net.http.HttpResponseCache.install(directory, maxSize)); }
private static void flushHttpCache() { HttpResponseCache cache = HttpResponseCache.getInstalled(); if (cache != null) { cache.flush(); } }
@Override public CacheRequest put(URI uri, URLConnection connection) throws IOException { return delegate.put(uri, connection); }
@Override public CacheResponse get(URI uri, String requestMethod, Map<String, List<String>> requestHeaders) throws IOException { return delegate.get(uri, requestMethod, requestHeaders); }